Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

psql

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?

like image 279
Lisa Avatar asked Sep 25 '14 13:09

Lisa


People also ask

How do I show data in PostgreSQL?

Another way to show tables in PostgreSQL is to use the SELECT statement to query data from the PostgreSQL catalog as follows: Syntax: SELECT * FROM pg_catalog. pg_tables WHERE schemaname != 'pg_catalog' AND schemaname !=

How do you show data in a table?

To display the rows from a particular table or tables: Double-click the table name in the grid. Select names of tables in the grid, then right-click and select Display Rows from the shortcut menu, or select Display Rows from the File menu.

How do I view a specific table in PostgreSQL?

Use the \dt or \dt+ command in psql to show tables in a specific database. Use the SELECT statement to query table information from the pg_catalog.

What is the psql command to show the schema of a relation?

Type the command \l in the psql command-line interface to display a list of all the databases on your Postgres server.


4 Answers

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.

like image 60
Craig Ringer Avatar answered Oct 05 '22 06:10

Craig Ringer


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

like image 27
Zan Zas Avatar answered Oct 05 '22 08:10

Zan Zas


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

like image 31
israteneda Avatar answered Oct 05 '22 08:10

israteneda


you should use quotes

example =>

1) \c mytablename
2) SELECT * FROM "mytablename";  OR TABLE "mytablename";
like image 21
luka Avatar answered Oct 05 '22 06:10

luka