Basic INSERT
suggest changeLet’s say we have a simple table called person:
CREATE TABLE person (
person_id BIGINT,
name VARCHAR(255),
age INT,
city VARCHAR(255)
);
The most basic insert involves inserting a value for every column, in table order:
INSERT INTO person VALUES (1, 'john doe', 25, 'new york');
If you want to insert only specific columns, you need to explicitly indicate which columns:
INSERT INTO person (name, age) VALUES ('john doe', 25);
Note that if any constraints exist on the table, such as NOT NULL, you will be required to include those columns in either case. Columns with defaults, including serial, can be omitted.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents