PostgreSQL sql命令错误列'不存在'

时间:2015-03-04 07:54:15

标签: insert

dxdb=> \d dxtest_loadprofiletosale
                            Table "public.dxtest_loadprofiletosale"
   Column    |   Type   |                               Modifiers                               
-------------+----------+-----------------------------------------------------------------------
 id          | integer  | not null default nextval('dxtest_loadprofiletosale_id_seq'::regclass)
 TransDate   | date     | 
 IssueDate   | date     | 
 CustomerNum | smallint | not null
Indexes:
    "dxtest_loadprofiletosale_pkey" PRIMARY KEY, btree (id)

dxdb=> INSERT INTO dxtest_loadprofiletosale(id, TransDate, IssueDate, CustomerNum) VALUES(1, '2015-03-04','2015-01-01',01);
ERROR:  column "transdate" of relation "dxtest_loadprofiletosale" does not exist
LINE 1: INSERT INTO dxtest_loadprofiletosale(id, TransDate, IssueDat...

不好意思,我已经有了“transdate”专栏,为什么它说不存在?

1 个答案:

答案 0 :(得分:8)

您的专栏名为"TransDate"而不是transdate。您使用列引号的双引号创建了表格,这使得它们区分大小写,您必须使用双引号所有时间:

INSERT INTO dxtest_loadprofiletosale
  (id, "TransDate", "IssueDate", "CustomerNum") 
VALUES
  (1, '2015-03-04','2015-01-01',01);

有关SQL标识符的更多详细信息,请参见手册:
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS

一般情况下,从不使用双引号会更好 - 从长远来看,它会给您带来更少的麻烦。