Postgresql 10 无法使用身份主键插入 table

Postgresql 10 unable to insert into table with identity primary key

我有以下 table 时间表。

 Table "public.timesheet"
       Column        |          Type          | Collation | Nullable |           Default            
---------------------+------------------------+-----------+----------+------------------------------
 timesheetid         | integer                |           | not null | generated always as identity
 employeeid          | integer                |           |          | 
 date_linkid         | integer                |           |          | 
 employee_functionid | integer                |           |          | 
 start_time          | time without time zone |           |          | 
 finish_time         | time without time zone |           |          | 
 note                | text                   |           |          | 
Indexes:
    "timesheet_pkey" PRIMARY KEY, btree (timesheetid)
Check constraints:
    "timesheet_time_check" CHECK (finish_time > start_time)
Foreign-key constraints:
    "timesheet_date_linkid_fkey" FOREIGN KEY (date_linkid) REFERENCES date_link(date_linkid)
    "timesheet_employee_functionid_fkey" FOREIGN KEY (employee_functionid) REFERENCES employee_function(employee_functionid)
    "timesheet_employeeid_fkey" FOREIGN KEY (employeeid) REFERENCES employee(employeeid)

当我运行以下命令时:

--INSERT TIMESHEET INFORMATION:
INSERT INTO timesheet (timesheetid,employeeid,date_linkid,employee_functionid,start_time,finish_time,note)
VALUES

        (DEFAULT,1,223,1,'13:56:00','16:40:00',NULL),
        (DEFAULT,1,223,3,'18:10:00','18:19:00',NULL)
;

我收到以下错误消息:

ERROR:  cannot insert into column "timesheetid"
DETAIL:  Column "timesheetid" is an identity column defined as GENERATED ALWAYS.
HINT:  Use OVERRIDING SYSTEM VALUE to override.

我不知道我哪里出错了,因为我在执行了以下命令后再次尝试,仍然得到同样的错误信息。有人知道这里出了什么问题吗?

crewdb=# SELECT MAX(timesheetid) FROM timesheet;
 max 
-----
 418
(1 row)

crewdb=# SELECT nextval('timesheet_timesheetid_seq');
 nextval 
---------
     419
(1 row)

crewdb=# BEGIN;
BEGIN
crewdb=# SELECT setval('timesheet_timesheetid_seq', COALESCE((SELECT MAX(timesheetid)+1 FROM timesheet), 1), false);
 setval 
--------
    419
(1 row)

crewdb=# COMMIT;
COMMIT

如果 timesheetid 是一个自动生成的列,您应该能够简单地从插入的列列表中完全省略它:

INSERT INTO timesheet (employeeid, date_linkid, employee_functionid, start_time,
    finish_time, note)
VALUES
    (1, 223, 1, '13:56:00', '16:40:00', NULL),
    (1, 223, 3, '18:10:00', '18:19:00', NULL);

Postgres 将自动生成 timesheetid 的值。