3 ms·
psql with right query and right flag can do that.
by bagol 7y ago
psql with right query and right flag can do that.
- daniub 7y agoCan you share that query and flag please?
- kbaker 7y agoI was sure most of this existed so I looked it up... Mostly centers around adding row_to_json() to the query. Using the example from the github repo: $ psql -P pager -nqtc "select row_to_json(pg_database) from pg_database where datname = 'template0'" | jq { "datname": "template0", ... "datacl": [ "=c/postgres", "postgres=CTc/postgres" ] }
- bagol 7y agoUse --tuples-only / -t and --no-align / -A. Or -tA for short. For example: $ psql dbname -tAc 'SELECT json_agg(some_table) FROM some_table' That will produce a valid JSON if you ever need to pipe it to another command. And I'm sure, psql will do the job a lot faster than node. By the way, you should not underestimate the built-in psql power and postgresql's json capability. Postgresql's JSON power rivals that of other JSON based No-SQL databases.