Skip to content

Instantly share code, notes, and snippets.

@corbanb
Last active June 11, 2016 19:11
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 corbanb/84c28da42c5a04cf4bdf to your computer and use it in GitHub Desktop.
Save corbanb/84c28da42c5a04cf4bdf to your computer and use it in GitHub Desktop.
PostgreSQL Useful commands

psql commands

Export to CSV

$ psql postgres://user:pass@localhost:1337/dbname -o 'file.csv' -F , --no-align -c 'SELECT * FROM column ORDER BY created_at ASC;'

Arrays

UPDATE "Jobs" SET "subscribers" = array_replace("subscribers", 'corbanb+plan@gmail.com', 'corbanb+plan2@gmail.com') WHERE "deletedAt" IS NULL AND 'corbanb+plan@gmail.com' = ANY ("subscribers")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment