简体   繁体   English

psql 查询中时间戳的无法解释的语法错误

[英]Unexplainable syntax error on a timestamp in a psql query

I am having a syntax error on a psql query which is really strange, as my syntax seems right我在 psql 查询中遇到语法错误,这真的很奇怪,因为我的语法似乎是正确的

INSERT INTO functionMonitoring (function, startDate, endDate, type, severity, status, text) values('test', 2019-07-16 17:04:53.866, 2019-07-16 17:04:53.866, 'process', 'INFORMATION', 'OK', 'Some random stuff');

This is my query, but typing it in my psql console gives this :这是我的查询,但在我的 psql 控制台中输入它会给出:

ERROR:  syntax error at or near "17"
LINE 1: ...severity, status, text) values('test', 2019-07-16 17:04:53.8...
                                                             ^

I don't understand why this happens.我不明白为什么会发生这种情况。 It is not a type problem as I already checked for each column's type and my table already holds similar data.这不是类型问题,因为我已经检查了每列的类型并且我的表已经包含类似的数据。 Here is one exemple line already in my table这是我的表格中已有的一行示例

 id |    function    |          startdate           |           enddate            |  type   | severity | status |                  text
----+----------------+------------------------------+------------------------------+---------+----------+--------+----------------------------------------
  4 | DBReaderWindow | Tue Jul 16 16:15:41.144 2019 | Tue Jul 16 16:15:42.779 2019 | process | LOW      | OK     | Function fully executed with no errors

I hope I gave enough information to resolve the problem, thank you for your help !我希望我提供了足够的信息来解决问题,谢谢您的帮助!

You are missing a single quote to start the string literal that contains your timestamp:您缺少一个单引号来开始包含您的时间戳的字符串文字:

INSERT ... VALUES ('test', '2019-07-16 17:04:53.8', ...)
                           ^                     ^

Without them, PostgreSQL interprets 2019-07-16 as an arithmetic expression (equivalent to 1996) and does not expect the following 17 .没有它们,PostgreSQL 将2019-07-16解释为一个算术表达式(相当于 1996)并且不期望下面的17

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM