Skip to content
Advertisement

Querying JSON in POSTGRESQL returns NONE everytime

jsonb column text_results contains values in the following form : {‘Name’ : ‘john doe’ , ‘id’ : ‘123’}

On querying

Select text_results->>'Name' as Name from user_master

or

Select json_extract_path_text(text_results::json,'Name') as name from user_master

it always return None without any error even though values are present.

Need help with rectifying the error or any other way of extracting values from json column in POSTGRESQL.

Thanks in advance!

Advertisement

Answer

Your query works as expected provided that JSON syntax is correct using double quotes. Here is an illustration.

with user_master(text_results) as 
(
 values ('{"Name": "john doe", "id": 123}'::jsonb)
)
select text_results->>'Name' as Name from user_master;

-- john doe
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement