Postgresql insert without id

When inserting data into a PostgreSQL table without explicitly specifying the value for the ID column, you can use the INSERT statement.

Here is an example:

CREATE TABLE example (
  id SERIAL PRIMARY KEY,
  name VARCHAR(100)
);

INSERT INTO example (name) VALUES ('John Doe');

In this example, a table named “example” is created with two columns: “id” and “name”. The “id” column is defined as a SERIAL type, which automatically generates a unique numerical ID for each inserted row.

The INSERT INTO statement is used to insert a new row into the “example” table. We only specify the value for the “name” column and omit the “id” column. PostgreSQL will automatically generate a value for the “id” column.

After executing the INSERT statement, a new row is added to the “example” table with a unique value for the “id” column and the provided value for the “name” column.

Leave a comment