postgreSQL Table Creation
Table creation with Primary Key
Alternatively, you can place the PRIMARY KEY constraint directly in the column definition:
It is recommended that you use lower case names for the table and as well as all the columns. If you use upper case names such as Person you would have to wrap that name in double quotes ("Person") in each and every query because PostgreSQL enforces case folding.
Show table definition
Open the psql command line tool connected to the database where your table is. Then type the following command:
To get extended information type
If you have forgotten the name of the table, just type \d into psql to obtain a list of tables and views in the current database.
Create table from select
Let's say you have a table called person:
You can create a new table of people over 30 like this:
Create unlogged table
You can create unlogged tables so that you can make the tables considerably faster. Unlogged table skips writing write-ahead log which means it's not crash-safe and unable to replicate.
Create a table that references other table.
In this example, User Table will have a column that references the Agency table.