sql - 错误 : column of relation does not exist PostgreSQL , 无法运行插入查询

标签 sql postgresql sql-insert quoted-identifier

您好,我正在尝试插入表 tester3,当我使用语法时它失败了

insert into tester3 (UN0, UN1) values ( 1, 'jishnu1');

但是

insert into tester3 values ( 1, 'jishnu1');

工作正常。

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) |

我想我遗漏了一些非常微不足道的东西,我尝试了一些其他的列名,其中一些可以正常工作,而另一些则不起作用。我很困惑。 PostgreSQL 是否对插入查询的第一种语法起作用的列名有限制?


编辑:

检查 Girdon Linoff 的 answer在这里,作为 Frank Heikens指出其他没有引号的列名是小写

Lower case column is the standard within PostgreSQL and also works without quotes

最佳答案

如果用双引号定义列,那么在引用列时一般需要使用它们:

insert into tester3 ("UN0", "UN1")
     values ( 1, 'jishnu1');

我建议您从 CREATE TABLE 语句中的列名中删除双引号。

如果名称全部小写,则不需要双引号。

关于sql - 错误 : column of relation does not exist PostgreSQL , 无法运行插入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31072143/

相关文章:

c# - 错误 : The conversion of a nvarchar data type to a smalldatetime data type resulted in an out-of-range value

mysql - 如果特定列存在字段,如何更新

sql - 将 WITH 语句重写为 SQL 中的子查询语句?

mysql - 如何打印分组得到的查询结果的各个值

ruby-on-rails - 在 PGSQL ActiveRecord 中构建与自定义字符串外键的一对多关系

python - (Python/Django) : How do I keep my production db in sync (scheme and data) and with dev pc db?

windows - postgres COPY (...) TO PROGRAM on Windows 给出错误

php - PHP 中的 INSERT 查询失败(返回空白错误)

mysql - 仅考虑 COUNT 个特定 ID

c# - 在循环内添加SQL参数,在循环外执行。 (在 C# SQL 客户端中使用参数进行单查询多插入)