PostgreSQL 错误:INSERT 的目标列多于表达式,当它没有时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27639239/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:51:07  来源:igfitidea点击:

PostgreSQL ERROR: INSERT has more target columns than expressions, when it doesn't

postgresql

提问by John

So I'm starting with this...

所以我从这个开始......

SELECT * FROM parts_finishing;

...I get this...

……我明白了……

id, id_part, id_finish, id_metal, id_description, date, inside_hours_k, inside_rate, outside_material

(0 rows)

id、id_part、id_finish、id_metal、id_description、日期、inside_hours_k、inside_rate、outside_material

(0 行)

...so everything looks fine so far so I do this...

......所以到目前为止一切看起来都很好所以我这样做......

INSERT INTO parts_finishing 
(
 id_part, id_finish, id_metal, id_description, 
 date, inside_hours_k, inside_rate, outside_material
) VALUES (
('1013', '6', '30', '1', NOW(), '0', '0', '22.43'), 
('1013', '6', '30', '2', NOW(), '0', '0', '32.45'));

...and I get...

……我明白了……

ERROR: INSERT has more target columns than expressions

错误:INSERT 的目标列多于表达式

Now I've done a few things like ensuring numbers aren't in quotes, are in quotes (would love a table guide to that in regards to integers, numeric types, etc) afterI obviously counted the number of column names and values being inserted. I also tried making sure that all the commas are commas...really at a loss here. There are no other columns except for idwhich is the bigserialprimary key.

现在我已经做了一些事情,比如确保数字不在引号中,在引号中(希望有关于整数、数字类型等的表格指南),我显然计算了列名和值的数量之后插入。我还尝试确保所有逗号都是逗号……在这里真的很茫然。还有,除了没有其他列id这是bigserialprimary key

回答by wildplasser

Remove the extra ():

删除额外的()

INSERT INTO parts_finishing 
(
 id_part, id_finish, id_metal, id_description, 
 date, inside_hours_k, inside_rate, outside_material
) VALUES 
  ('1013', '6', '30', '1', NOW(), '0', '0', '22.43')
, ('1013', '6', '30', '2', NOW(), '0', '0', '32.45')
  ;

回答by 2dor

I had a similar problem when using SQLstring composition with psycopg2in Python, but the problem was slightly different. I was missing a comma after one of the fields.

我在Python 中使用SQL字符串组合时遇到了类似的问题,但问题略有不同。我在其中一个字段后遗漏了一个逗号。psycopg2

INSERT INTO parts_finishing
(id_part, id_finish, id_metal)
VALUES (
    %(id_part)s <-------------------- missing comma
    %(id_finish)s,
    %(id_metal)s
);

This caused psycopg2to yield this error:

这导致psycopg2产生此错误:

ERROR: INSERT has more target columns than expressions.

错误:INSERT 的目标列多于表达式。

回答by Christophe Roussy

This happened to me in a large insert, everything was ok (comma-wise), it took me a while to notice I was inserting in the wrong tableof course the DB does not know your intentions. Copy-paste is the root of all evil ... :-)

这发生在我的大插入中,一切正常(逗号),我花了一段时间才注意到我插入了错误的表,当然数据库不知道你的意图。复制粘贴是万恶之源... :-)

回答by Mr S Coder

I have the same error on express js with PostgreSQL

我在使用 PostgreSQL 的 express js 上有同样的错误

I Solved it. This is my answer.

我解决了。这是我的回答。

error fire at the time of inserting record.

插入记录时发生错误。

error occurred due to invalid column name with values passing

error: INSERT has more target columns than expressions

ERROR : error: INSERT has more target columns than expressions name: 'error', length: 116, severity: 'ERROR', code: '42601', detail: undefined, hint: undefined, position: '294', internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'analyze.c', line: '945',

由于传递的值无效的列名而发生错误

错误:INSERT 的目标列多于表达式

错误:错误:插入的目标列多于表达式名称:'错误',长度:116,严重性:'错误',代码:'42601',详细信息:未定义,提示:未定义,位置:'294',内部位置:未定义, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'analyze.c', line: '945',

here is my code dome

这是我的代码圆顶

INSERT INTO student(
  first_name, last_name, email, phone
) 
VALUES 
  (, , , ), 
values 
  : [ first_name, 
  last_name, 
  email, 
  phone ]

回答by Hari Bharathi

I faced the same issue as well.It will be raised, when the count of columns given and column values given is mismatched.

我也遇到了同样的问题。当给定的列数和给定的列值不匹配时,它会被引发。