简体   繁体   English

如何让 postgres 告诉哪个列导致错误

[英]How to make postgres tell which column is causing an error

While inserting data into a table which has many columns:在将数据插入到具有许多列的表中时:

INSERT INTO MyTable ("name", ..100+ columns)
 VALUES ('Michel', ... 100+ values)

I made an error creating a specific value so PostgreSQL tells us:我在创建特定值时出错,因此 PostgreSQL 告诉我们:

ERROR:  value too long for type character varying(2)

I would like to avoid going through the whole table schema to guess which column is failing.我想避免通过整个表模式来猜测哪一列失败了。

Is there a way to configure PostgreSQL so it tells us which column is causing the error?有没有办法配置 PostgreSQL 所以它告诉我们哪一列导致了错误?

One quick way might be to query the information schema table for your database and look for character columns having a maximum width of 2 (to which your error is alluding):一种快速的方法可能是查询数据库的信息模式表并查找最大宽度为 2 的字符列(您的错误暗示):

SELECT column_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'MyTable' AND
      character_maximum_length = 2;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM