【发布时间】:2016-11-09 17:53:55
【问题描述】:
INSERT into Group (Name,CreatedDate) VALUES ('Test',UTC_TIMESTAMP(), 1);
这是我用于 mysql 插入当前日期时间的查询。 当我在 postgresql 中使用它时,出现以下错误。
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
********** Error **********
ERROR: function utc_timestamp() does not exist
SQL state: 42883
我尝试过如下使用now(),但是它像"2016-07-07 17:01:18.410677" 一样插入。我需要以'yyyymmdd hh:mi:ss tt' 格式插入。
INSERT into Group (Name,CreatedDate) VALUES ('Test',UTC_TIMESTAMP(), 1);
如何在上述格式的postgresql的插入查询中插入当前日期时间?
【问题讨论】:
-
也许搜索
CURRENT_TIMESTAMP或什至NOW()。前者至少有精确的论据。所以CURRENT_TIMESTAMP(3)将产生 3 个亚秒位数(毫秒分辨率) -
... 通过 SET DATESTYLE 进行格式化,例如。 at:in postgres, can you set the default formatting for a timestamp, by session or globally? 或在官方 postgres 文档中
-
timestamp列确实不具有“格式”。您看到的任何格式都由您使用的 SQL 客户端应用。如果您想要不同的 display 格式,请更改 SQL 客户端的配置或使用正确的格式化函数。 -
是的,它在 MySQL 上运行,但现在您希望它在 Postgresql 中运行,因此您需要在 Postgresql 手册中查找等效函数。
标签: postgresql datetime insert