Skip to content

Instantly share code, notes, and snippets.

@bwestergard
Created February 29, 2016 22:23
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bwestergard/d8d522c1f09dba03ee4a to your computer and use it in GitHub Desktop.
Save bwestergard/d8d522c1f09dba03ee4a to your computer and use it in GitHub Desktop.
json_populate_recordset example
lanetix=# \d foo
           Table "scripting.foo"
 Column |         Type          | Modifiers 
--------+-----------------------+-----------
 id     | integer               | not null
 a      | character varying(40) | not null
 b      | character varying(40) | not null
 c      | character varying(40) | not null

lanetix=# BEGIN; DELETE FROM foo; INSERT INTO foo SELECT * from json_populate_recordset(null::foo, '[ {"id": 0, "a": "harold", "b": "wilson", "c": "j"}, {"id": 1, "a": "brian", "b": "wilson", "c": "q"}, {"id": 2, "a": "jack", "b": "kemp", "c": "q"} ]'); COMMIT;
BEGIN
DELETE 0
INSERT 0 3
COMMIT
lanetix=# select * from foo;
 id |   a    |   b    | c 
----+--------+--------+---
  0 | harold | wilson | j
  1 | brian  | wilson | q
  2 | jack   | kemp   | q
(3 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment