List tables, in current db
\dt
SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;
List tables, globally
\dt \*.\*.
SELECT \* FROM pg_catalog.pg_tables
List table schema
\d <table_name>
\d+ <table_name>
SELECT column_name, data_type, character_maximum_length
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = '<table\_name>';
CREATE TABLE <table_name>(
<column_name> <column_type>,
<column_name> <column_type>
);
Create table, with an auto-incrementing primary key
CREATE TABLE <table_name> (
<column_name> SERIAL PRIMARY KEY
);
DROP TABLE IF EXISTS <table_name> CASCADE;
Comments