Skip to main content

psql

psql is PostgreSQL's interactive terminal client. It works directly with SereneDB.

Connect​

sh
psql -h localhost -p 7890

Useful commands​

CommandDescription
\lList databases
\dList tables
\d table_nameDescribe a table
\d+List tables with sizes
\i file.sqlExecute a SQL file
\timingToggle query timing
\qQuit

Running queries​

Run any SQL statement at the prompt and terminate it with a semicolon:

SQL
SELECT title, rating FROM movies WHERE year > 2015 ORDER BY rating DESC LIMIT 5;
 title             | rating
-------------------+--------
 Intro to Search   |    9.5
 Scaling Analytics |    8.1
 The Last Index    |    7.7

Importing CSV​

Use the server-side COPY ... FROM statement to load a CSV file into an existing table:

SQL
COPY movies FROM 'movies.csv' WITH (FORMAT CSV, HEADER TRUE);

Tips​

  • Use Tab to auto-complete table and column names
  • Press Ctrl+R to search command history
  • Use \timing to benchmark queries