Skip to content

Instantly share code, notes, and snippets.

@plindberg
Last active July 4, 2018 07:39
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 plindberg/de660d0b37c4bbd5a180b4f1fee2b271 to your computer and use it in GitHub Desktop.
Save plindberg/de660d0b37c4bbd5a180b4f1fee2b271 to your computer and use it in GitHub Desktop.
Dump PostgreSQL table with JSONB column, qualifying by some JSON value, formatting for presentation using Heroku Dataclips
SELECT
TO_CHAR(created_at::timestamptz AT TIME ZONE 'CEST', 'YYYY-MM-DD HH24.MI.SS') AS "Date",
(json->>'firstName') || ' ' || (json->>'lastName') AS "Name",
json->>'email' AS "Email",
json->>'phone' AS "Phone",
json->>'whatever' AS "Whatever",
json#>>'{stuff, 0}' AS "Stuff 1",
json#>>'{stuff, 1}' AS "Stuff 2",
json#>>'{stuff, 2}' AS "Stuff 3"
FROM some_table
WHERE something = 'whatever' AND
json->>'whatever' IN ('whatever', 'something else', 'another thing')
ORDER BY id DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment