Last active
February 23, 2020 01:39
-
-
Save ndastur/732117eabe9b8895389986a43dabc3c3 to your computer and use it in GitHub Desktop.
Output list of Postgresql tables and their fields on a single bash line
This file contains hidden or 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
PGUSER=<user> PGPASSWORD=<pw> PGHOST=<host> PGDATABASE=<database> bash -c 'psql -Atc "select tablename from pg_tables where schemaname='\''public'\''" $PGDATABASE | while read TBL; do echo \"$TBL\": { \"keyFields\": [ ; psql -c "COPY (select * from public.$TBL where false) TO STDOUT WITH (FORMAT CSV, HEADER, DELIMITER '\'','\'')" $PGDATABASE | sed '\''s/[^,]*/"&"/g'\'' ; echo ] }, ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment