如何 insert current datetime in postgresql insert query

INSERT into Group /Name,CreatedDate/ VALUES /'Test',UTC_TIMESTAMP//, 1/;


这是我使用的请求 mysql - insert 当前日期和时间。
当我使用它时 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"

. 我需要 insert 格式化
'yyyymmdd hh:mi:ss tt'

.


INSERT into Group /Name,CreatedDate/ VALUES /'Test',UTC_TIMESTAMP//, 1/;


如何 insert 当前日期和时间 insert 要求 postgresql 以上述格式 ?
已邀请:

二哥

赞同来自:

timestamp

/或者
date

或者
time

柱子/ 不是

有 "a format".

您所看到的任何格式都由客户端应用。 SQL, 您使用的。

为了 insert 当前时间使用
current_timestamp

,
https://www.postgresql.org/doc ... RRENT
:


INSERT into "Group" /name,createddate/ 
VALUES /'Test', current_timestamp/;




展示

此值采用另一种格式,更改客户端的配置。 SQL 或格式化值 SELECTing 数据:


select name, to_char/createddate, ''yyyymmdd hh:mi:ss tt'/ as created_date
from "Group"


为了
psql

/命令行客户端默认情况下/ 您可以使用配置参数配置日期显示格式。
DateStyle

:
https://www.postgresql.org/doc ... STYLE

帅驴

赞同来自:

适用于当前 datetime 您可以使用该功能 now// 询问 postgresql insert.

您还可以联系以下链接。

https://coderoad.ru/15530899/
.

八刀丁二

赞同来自:

当然,您可以格式化结果
current_timestamp//

.
请阅读官方的各种格式化功能
https://www.postgresql.org/doc ... .html
.

要回复问题请先登录注册