I have the following table
CREATE TABLE country (
id INTEGER NOT NULL PRIMARY KEY ,
name VARCHAR(50),
extra_info JSONB
);
INSERT INTO country(id,extra_info)
VALUES (1, '{ "name" : "France", "population" : "65000000", "flag_colours": ["red", "blue","white"]}');
INSERT INTO country(id,extra_info)
VALUES (2, '{ "name": "Spain", "population" : "47000000", "borders": ["Portugal", "France"] }');
SELECT extra_info->>'name' as Name, extra_info->>'population' as Population
FROM country
I would like to select id and extra info
SELECT id,extra_info->>'population' as Population,extra_info->'flag_colours'->>1 as colors
FROM country
This query shows only id,population but the flag_colors is null.
I also would like to use flag_colors in a condition
SELECT extra_info->>'population' as Population FROM country where extra_info->'flag_colours'->>0
i get this error
ERROR: argument of WHERE must be type boolean, not type text
LINE 1: ...o->>'population' as Population FROM country where extra_info...
^
SQL state: 42804
Character: 67
How can i fix the two queries?
flag_coloursin the data vsflag_colorsin the query