DATABASE » SQL » POSTGRESQL

Queries

Database

sql
CREATE DATABASE dbname;
DROP DATABASE dbname;
CommandDescription
\c DBNAME \connect DBNAMEConnect to database.
\l \listList databases.
\q \quitQuit.

Table

CommandDescription
\dtDescribe (list) tables.
\d TABLEDescribe table.

Display mode

Use \x to toggle the way to display query results (table or expanded).

It is also possible to use \gx to apply expanded formatting mode for the current query only.

txt
SELECT * FROM my_table \gx

Functions

sql
SELECT COALESCE(title, 'NULL') AS title FROM posts;
SELECT LEFT(nick,10) FROM users;