Created
May 11, 2018 10:26
-
-
Save chetanppatil/191cbc1c1b447f894a5cc65e61d0cb5f to your computer and use it in GitHub Desktop.
Select data from json and insert it into single row and multiple column
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE my_table(col text, col2 text) | |
/* SELECT DATA FROM JSON */ | |
SELECT * FROM json_each('{"a":"foo", "b":"bar"}') AS e | |
/* INSERT INTO TABLE */ | |
INSERT INTO my_table(col, col2) | |
SELECT * FROM json_to_record('{"a":"foo", "b":"bar"}') AS x(col text, col2 text) -- as can have different column name | |
SELECT * FROM my_table | |
/* UPDATE RECORD IN my_table */ | |
UPDATE my_table | |
SET col = x.a, col2 = x.b | |
FROM json_to_record('{"a":"11111", "b":"bar222"}') AS x(a text, b text) | |
WHERE col='foo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment