gpt4 book ai didi

postgresql - 为什么 'now()'::timestamp 在 PostgreSQL 中返回当前时间戳?

转载 作者:行者123 更新时间:2023-11-29 12:43:48 27 4
gpt4 key购买 nike

一个简单的例子:

select 'now()'::timestamp;

给予

2016-03-12 07:52:46.1

注意 now() 函数调用周围的单引号。

我认为 now() 函数调用被单引号转义,数据库应该只输出 now()。但我在 Postgres 9.0 和 8.4 上对此进行了测试,结果均为 2016-03-12 07:52:46.1

当我将 'now()'(注意单引号)显式插入到 timestamp 类型的字段时,同样的事情会发生。

但如果不应用到timestamp的隐式转换,它只会输出'now()',例如:

select 'now()';

给出:

now()

而且我注意到这种“未转义”只发生在 now 上,因为我测试了对其他函数的调用可以通过单引号正确转义。

对此我没有找到合理的解释,有谁能给点建议吗?

最佳答案

这是conversion from string to timestamp or date/time type的一个特殊函数;括号是多余的,因为它不是真正的函数调用。我非常怀疑添加该特定值是为了用作时间戳列的特殊默认值。

关于postgresql - 为什么 'now()'::timestamp 在 PostgreSQL 中返回当前时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35952107/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com