I am trying to write a PostgreSQL script that meets the following requirements:
- Create a table with two columns, Id and Id2, which must always have identical values when a record is added to the table (this design is intentional and cannot be changed).
- Use a sequence to generate values for Id.
- Be executed from C# code, not from any PostgreSQL management tool like pgAdmin.
I tried with the following script but it failed:
CREATE SEQUENCE IF NOT EXISTS myTable_seq
START 1
INCREMENT 1
MINVALUE 1
MAXVALUE 2147483647
CACHE 1;
CREATE TABLE IF NOT EXISTS myTable
(
     id bigint NOT NULL nextval('myTable_seq'),
     symbol bigint NOT NULL currval('myTable_seq'),
     CONSTRAINT PK_myTable_Id PRIMARY KEY (Id)
)
I got:
ERROR: syntax error at or near 'nextval' 



DEFAULTkeyword...id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,idandsymbolto be the same and if you usedGENERATED ALWAYS AS IDENTITYon each column they would not.CREATE TABLE IF NOT EXISTS myTable ( id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY (SEQUENCE NAME myTable_seq), symbol bigint NOT NULL DEFAULT currval('myTable_seq') );