How to show data in a table by using psql command line interface?

Psql

Psql Problem Overview


Is there a way to show all the content inside a table by using psql command line interface?

I can use \list to show all the databases, \d to show all the tables, but how can I show all the data in a table?

Psql Solutions


Solution 1 - Psql

Newer versions: (from 8.4 - mentioned in release notes)

TABLE mytablename;

Longer but works on all versions:

SELECT * FROM mytablename;

You may wish to use \x first if it's a wide table, for readability.

For long data:

SELECT * FROM mytable LIMIT 10;

or similar.

For wide data (big rows), in the psql command line client, it's useful to use \x to show the rows in key/value form instead of tabulated, e.g.

 \x
SELECT * FROM mytable LIMIT 10;

Note that in all cases the semicolon at the end is important.

Solution 2 - Psql

Step 1. Check the display mode is "on" by using

\x

Step 2. Don't forget the ;

I tried for fifteen minutes just because I forgot the semicolon.

AND USE UPPERCASE ENGLISH.

TABLE users;

And you will get something like

enter image description here

Solution 3 - Psql

On Windows use the name of the table in quotes: TABLE "user"; or SELECT * FROM "user";

Solution 4 - Psql

you should use quotes

example =>

1) \c mytablename
2) SELECT * FROM "mytablename";  OR TABLE "mytablename";

Solution 5 - Psql

postgres commande line

  1. to show databases : \l
  2. to show tables : \dt
  3. to show data in table x : SELECT * FROM "x";
  4. to exit : \q

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLisaView Question on Stackoverflow
Solution 1 - PsqlCraig RingerView Answer on Stackoverflow
Solution 2 - PsqlZan ZasView Answer on Stackoverflow
Solution 3 - PsqlisratenedaView Answer on Stackoverflow
Solution 4 - PsqllukaView Answer on Stackoverflow
Solution 5 - PsqlElhem NouriView Answer on Stackoverflow