PostgreSQL psql Commnads - ghdrako/doc_snipets GitHub Wiki
Alternativ to pgsql: https://github.com/dbcli/pgcli
Using psql variables
\set foo 1
SELECT :foo;
The meta-commands you run in psql perform SQL queries behind the scenes. You can see them by setting this variable
\set ECHO_HIDDEN on
Once set, run any meta-command to see the SQL query printed out.
Description | Meta-Command |
---|---|
\l |
List databases. This is the letter “l” and not the number 1. |
\d |
Describe all objects (tables,views, sequences ...) |
\dn+ |
Describe schemas (namespaces) |
\dt |
Describe all tables |
\dv |
Describe views |
\d+ |
Describe definition when used with a view |
\x |
Toggle expanded display |
\! clear |
Clear the screen |
\! <shell command> |
Execute shell command |
\o <file-name> |
Ustawienie zbioru do ktorego zapisze sie wynika nastepnych kommend a zdo wpisanie \o
|
\set |
Set a psql variable e.g. \set foo 1 and use in statement SELECT :foo;
|
\e |
Edit queries in EDITOR |
\df |
Describe functions |
\dx |
Describe extensions |
\di * |
Describe indexes that match pattern, e.g. \di index_users*
|
\dRs+ |
Describe subscriptions |
\! clear |
Clear the screen |
\set |
Set a psql variable |
\g |
Execute the last command again |
\s |
Display command history |
\s filename |
Save the command history to a file |
\i filename |
Execute psql commands from a file |
\? |
Know all available psql commands |
\h |
Get help |
\e |
Edit command in your own editor |
\a |
Switch from aligned to non-aligned column output |
\H |
Switch the output to HTML format |
\q |
Exit psql shell |