5

I am using Dbeaver to create a Postgres database table but am getting a syntax error when using "GENERATED ALWAYS AS IDENTITY" for my incremented id value. It is strange because I used the exact same syntax when creating the table on my localhost and had no problem with any syntax errors or creating the table.

This is the SQL preview I have when attempting to save the table:

CREATE TABLE public.conversation (
    id bigint NOT NULL GENERATED ALWAYS AS IDENTITY,
    startdatetime timestamptz NOT NULL,
    enddatetime timestamptz NOT NULL,
    CONSTRAINT conversation_pk PRIMARY KEY (id)
);

When I try to save the table, I get "ERROR: syntax error at or near 'GENERATED'". I thought this was correct syntax considering the SQL is built by Dbeaver itself and it worked fine when creating a local database to test on?

ronhoward
  • 61
  • 2
  • 6

1 Answers1

2

Just use bigserial:

CREATE TABLE public.conversation (
    id bigserial primary key,
    startdatetime timestamptz NOT NULL,
    enddatetime timestamptz NOT NULL
);
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • a `bigserial` behaves a bit different to a `generated always as identity` –  Jun 25 '19 at 18:48
  • @a_horse_with_no_name . . . They are similar enough if for some reason the OP cannot use `generated always as identity`. – Gordon Linoff Jun 04 '20 at 12:50
  • 2
    absolutely, that's why I suggested to use it in my comments to the question itself. I just wanted to point out, that there are slight differences. –  Jun 04 '20 at 12:50