SQL 错误:关系列不存在 PostgreSQL,无法运行插入查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31072143/
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
ERROR: column of relation does not exist PostgreSQL ,Unable to run insert query
提问by Jishnu Prathap
Hi I am trying to insert into a table tester3 it fails when i use the syntax
嗨,我正在尝试将表 tester3 插入到表中,但当我使用语法时它失败了
insert into tester3 (UN0, UN1) values ( 1, 'jishnu1');
but
但
insert into tester3 values ( 1, 'jishnu1');
is working fine.
工作正常。
mydb=# CREATE TABLE tester3
mydb-# (
mydb(# "UN0" integer,
mydb(# "UN1" VARCHAR(40)
mydb(# );
CREATE TABLE
mydb=# insert into tester3 (UN0, UN1) values ( 1, 'jishnu1');
ERROR: column "un0" of relation "tester3" does not exist
mydb=# \d tester3
Table "public.tester3"
Column | Type | Modifiers
--------+-----------------------+-----------
UN0 | integer |
UN1 | character varying(40) |
I think i am missing something very trivial, I tried someother column names some of them works fine and some are not working. I am confused. Does PostgreSQL have restriction in column names for which works the 1st syntax of insert query works?
我想我遗漏了一些非常微不足道的东西,我尝试了一些其他的列名,其中一些工作正常,而有些则不起作用。我很迷惑。PostgreSQL 对插入查询的第一种语法起作用的列名是否有限制?
Edit :
编辑 :
Checkout Girdon Linoff answer and as Frank Heikenspointed out the other column names which was working without quotes where in lower case.
结帐 Girdon Linoff 的回答,正如Frank Heikens指出的其他列名,这些列名在小写的情况下没有引号。
Lower case column is the standard within PostgreSQL and also works without quotes
小写列是 PostgreSQL 中的标准,也可以不使用引号
回答by Gordon Linoff
If you define the columns with double quotes, then you generally need to use them when you refer to the column:
如果用双引号定义列,那么在引用列时一般需要使用它们:
insert into tester3 ("UN0", "UN1")
values ( 1, 'jishnu1');
I would suggest you remove the double quotes from the column names in the CREATE TABLE
statement.
我建议您从CREATE TABLE
语句中的列名中删除双引号。
You don't need the double quotes if the name is all lower case.
如果名称全部为小写,则不需要双引号。
回答by Ameya Deshpande
try this using double quotes to your column names
尝试在您的列名中使用双引号
insert into tester3 ("UN0", "UN1") values ( 1, 'jishnu1');