How to convert postgres json to integer
json, postgresql
Solution
What works for me (using posgtgresql 5.6) is
SELECT (tablename.jsoncolumnname->>'jsonfiledname')::int FROM tablename;
like
SELECT (users.data->>'failed_login_attempts_count')::int FROM users;
Assuming `users` table has a json column named `data` which is something like:
{"failed_login_attempts_count":"2","comment":"VIP"}
Problem
I can use `to_json(1)` to cast int to json, but how can I convert json to int? This may be too slow: ``` to_json(1)::text::int ``` Also, is json wrapped from a binary block (bson) or a simple wrapper of text?