psql is Awesome
See https://mydbanotebook.org/conf_talks.html and search for psql is Awesome
for the slides and video.
You can get tips at https://psql-tips.org/
Service File
This file is a config file to connect to a service.
| |
Then you can connect to psql:
| |
Settings
To get the number of rows for the previous query
| |
To default keywords to lowercase instead of upper case (ex. select instead of SELECT):
| |
If you want to see the details:
| |
If you only want the last query result:
| |
Working everyday with psql
To show the query that has too many columns:
| |
To repeat the last query:
| |
To output data to csv and read it back:
| |
\o without any options will stop saving to file.
Keep in mind that \! will enable you to run any CLI command.
Note that if you are using Windows, you may have problems running commands
since it appears to use cmd.exe instead of PowerShell.
You can use \i can run a query file (ex. \i query.sql).
Getting Deeper
\watch 1 will repeat the query every 1 second.
\gdesc will look at the last query provide the type for each column.
| |
\gexec Will play the previous statement (ex. think statements that begin with
begin; and may end with rollback;).
#Echo_hidden #Comp_keyword_case #Show_all_results #Pset #Gdesc #Gexec #Postgresql #Laetitia Avrot #Psql #Service File #Row_count