I inserted a data into a table....I wanna see now whole table with rows and columns and data. How I can display it through command?
To do this in PL/pgSQL, use the PERFORM statement: PERFORM query ; This executes query and discards the result. Write the query the same way you would write an SQL SELECT command, but replace the initial keyword SELECT with PERFORM .
Description. psql is a terminal-based front-end to PostgreSQL. It enables you to type in queries interactively, issue them to PostgreSQL, and see the query results. Alternatively, input can be from a file or from command line arguments.
Username [postgres]: On a Mac or Windows, you are able to connect to the default instance by simply hitting enter at the shell or command prompt when trying to run psql and keying in the password.
psql -U username -d mydatabase -c 'SELECT * FROM mytable'
If you're new to postgresql and unfamiliar with using the command line tool psql
then there is some confusing behaviour you should be aware of when you've entered an interactive session.
For example, initiate an interactive session:
psql -U username mydatabase mydatabase=#
At this point you can enter a query directly but you must remember to terminate the query with a semicolon ;
For example:
mydatabase=# SELECT * FROM mytable;
If you forget the semicolon then when you hit enter you will get nothing on your return line because psql
will be assuming that you have not finished entering your query. This can lead to all kinds of confusion. For example, if you re-enter the same query you will have most likely create a syntax error.
As an experiment, try typing any garble you want at the psql prompt then hit enter. psql
will silently provide you with a new line. If you enter a semicolon on that new line and then hit enter, then you will receive the ERROR:
mydatabase=# asdfs mydatabase=# ; ERROR: syntax error at or near "asdfs" LINE 1: asdfs ^
The rule of thumb is: If you received no response from psql
but you were expecting at least SOMETHING, then you forgot the semicolon ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With