无法使简单的PostgreSQL插入工作 [英] cannot get simple PostgreSQL insert to work

查看:93
本文介绍了无法使简单的PostgreSQL插入工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在postgres表中做一个简单的插入,但是却收到一个错误,我试图插入的值被解释为列名

I'm trying to do a simple insert into a postgres table, but am getting an error that the value I'm trying to insert is being interpreted as a column name

INSERT INTO "imageTagBusinessMainCategory"
(id, businessMainCategory)
VALUES
(DEFAULT, "auto dealer")

其中id设置为主键,并且自动递增,而不是null。这些是我在phpPgAdmin中设置表格时打勾的框。

Where id is set up to be the primary key, and auto increment, and not null. Those are the boxes I ticked when I set up the table in phpPgAdmin.

虽然我遇到此错误:

ERROR: ERROR: column "auto dealer" does not exist
Query = INSERT
INTO "imageTagBusinessMainCategory"
(id, businessMainCategory)
VALUES
(DEFAULT,
"auto dealer")

我已将表名用双引号括起来,因为我读过< a href = https://stackoverflow.com/a/695312/1252748>在此处应该。

I've put my table name in double quotes, as I've read here I should.

并使用默认以自动增加ID,因为我已阅读这里应该。

And used DEFAULT to auto-increment the id as I've read here I should.

有什么想法吗?
谢谢!

Any ideas? Thanks!

推荐答案

使用'auto Dealer'代替。 PostgreSQL将 解释为标识符的引用,将'解释为字符串的引用。

Use 'auto dealer' instead. PostgreSQL interprets " as being quotes for identifiers, ' as being quotes for strings.

也:


  • 如果这是一个新项目,请不要使用大小写混合的表格; 必须在引用标识符名称的同时引用
    ,否则不能在
    的SQL语句中使用任何大小写。

  • If this is a new project, just don't use mixed case tables; it is a source of frustration later. Instead of being able to use any case in your SQL statements, you must both quote the identifier name and get the case correct.

无需指定 id / DEFAULT ,您是
,要求它做已经做的事情。我还没有遇到DBMS
,它要求您包括 columnName / DEFAULT 如果您希望将其设置为
,则将默认值放在列中,因此,我认为这对额外的KV
对不会产生什么影响对于以后阅读
您的代码的人来说,情况更清楚。

There is no need to specify id/DEFAULT, you're asking it to do what it would have done already. I haven't met a DBMS that requires you to include columnName/DEFAULT if you want it to put the default value in the column, so I don't think this extra KV pair is going to make what is happening clearer to anyone reading your code later.

这篇关于无法使简单的PostgreSQL插入工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆