将日期插入PostgreSQL:列和来自

Ale*_*ver 3 database postgresql

我无法date在PostgreSQL 9.6表中插入.

这是INSERT查询:

INSERT INTO rates (idproperty, from, to, price)
VALUES (1, '2017-03-14', '2017-04-30', 130);
Run Code Online (Sandbox Code Playgroud)

这就是结果:

ERROR:  syntax error at or near "from"
LINE 1: INSERT INTO rates (idproperty, from, to, price)
Run Code Online (Sandbox Code Playgroud)

fromto使用数据类型定义date.

谢谢

use*_*754 7

我相信你已经使用了postgresql保留字 - fromto创建了你的表.要在查询中使用它们,需要将它们括在引号中"

试试这种方式:

INSERT INTO rates (idproperty, "from", "to", price)
VALUES (1, '2017-03-14', '2017-04-30', 130);
Run Code Online (Sandbox Code Playgroud)


Gab*_*Gab 5

from并且to是PostgreSQL中的保留字。您需要使用以下命令将其转义"

-- This fails:

test=# SELECT from FROM rates;
ERROR:  syntax error at or near "FROM"
LINE 1: SELECT from FROM rates;
                    ^

-- This works:

test=# SELECT "from" FROM rates;
 from 
------
(0 rows)
Run Code Online (Sandbox Code Playgroud)

请参阅保留字列表:https : //www.postgresql.org/docs/current/static/sql-keywords-appendix.html