Skip to content

Instantly share code, notes, and snippets.

@peketamin
Last active May 11, 2019 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peketamin/848e385206ee0dba45bde07d50c8993e to your computer and use it in GitHub Desktop.
Save peketamin/848e385206ee0dba45bde07d50c8993e to your computer and use it in GitHub Desktop.
PostgreSQL: JSON query example
-- https://www.postgresql.org/docs/9.5/functions-json.html
WITH
virtual_table AS (SELECT key, value FROM jsonb_each('{"k": {"sub_key": 10}, "k2": {"sub_key": 20}}')),
extracted_values AS (SELECT value->'sub_key' AS sub_key FROM virtual_table)
SELECT * FROM extracted_values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment