Postgresql – “INSERT INTO res_partner () VALUES ()” failure (autoincrement in postgres)

auto-incrementinsertpostgresql

This is DDL for the table:

CREATE TABLE public.res_partner (
    id serial NOT NULL,
    CONSTRAINT res_partner_pkey PRIMARY KEY (id)
);

This is SQL:

insert into public.res_partner () values ();

and the error:

SQL Error [42601]: ERROR: syntax error at or near ")"
  Position: 33
$ psql --version
psql (PostgreSQL) 11.1 (Ubuntu 11.1-1.pgdg18.04+1)

I see that this statement is absolutely legal. My code worked 2-3 days ago (PHP with Doctrine). But now I cannot execute this statement from dBeaver client and from my app.

Best Answer

Your linked question is for MySQL which doesn't really have a track record for valid standard SQL - and having an empty column list or empty values list is far from being "legal" syntax in standard SQL or Postgres.

If you want to insert the default values you have two choices

insert into public.res_partner (id) values (default);

Or if you do not want to specify the column name, use:

insert into public.res_partner
default values;