【问题标题】:Error when I try to insert a timestamp value in PostgreSQL?尝试在 PostgreSQL 中插入时间戳值时出错?
【发布时间】:2012-09-12 03:55:26
【问题描述】:

我正在尝试插入以下值

('PA', 'Hilda Blainwood', 3, 10.7, 4308.20, '9/8/1974', '9:00', '07/03/1996 10:30:00');

进入表alltypes,结构如下

create table alltypes( state CHAR(2), name CHAR(30), children INTEGER, distance FLOAT,
budget NUMERIC(16,2), checkin TIME, started TIMESTAMP);

弹出如下错误

test=# insert into alltypes VALUES('PA', 'Hilda Blainwood', 3, 10.7, 4308.20, '9/8/1974',
'9:00', '07/03/1996 10:30:00');
ERROR:  INSERT has more expressions than target columns
LINE 1: ...Blainwood', 3, 10.7, 4308.20, '9/8/1974', '9:00', '07/03/199...

【问题讨论】:

    标签: postgresql sql-insert


    【解决方案1】:

    错误消息很容易解释:您正在尝试插入更多表具有列的值。您的表有七列,但您的 VALUES 表达式有八个值。

    顺便说一句,您应该始终在插入时指定列:

    insert into alltypes (state, name, children, distance, budget, checkin, started)
    values (...)
    

    【讨论】:

      猜你喜欢
      • 2012-03-10
      • 2020-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多