How to Set a Default Value for a Column in PostgreSQL
Give a PostgreSQL column a default value, so every insert that leaves it out gets that value.
- Database
- PostgreSQL
Give a PostgreSQL column a default value, so every insert that leaves it out gets that value.
SET changes a PostgreSQL setting for your own session only, and RESET puts it back, shown with the DateStyle setting.
WHERE keeps only the rows that match a condition. A small table of cities shows how to filter, and the mistake to avoid.
Read rows from a PostgreSQL table with SELECT … FROM: every column with *, or only the columns you name.
Add a row to a PostgreSQL table with INSERT INTO, its columns and VALUES, with a small address book.
Create a table in PostgreSQL with CREATE TABLE, and use IF NOT EXISTS when it may already be there.
Convert a value to another data type in PostgreSQL with :: or CAST, and see what happens when it can’t be converted.
In PostgreSQL, SELECT doesn’t need a table: SELECT 42 returns 42, a quick way to try a value.
Write dates in PostgreSQL year first, as YYYY-MM-DD after the DATE key word, so every server reads them the same way.
Write text in PostgreSQL between single quotes, and type a single quote twice to put one inside the text.