【发布时间】:2016-09-08 18:15:14
【问题描述】:
1> 在 AWS RedShift 中运行良好:
rep=# \d repdaily
Table "prod.repdaily"
Column | Type | Modifiers
---------------------------+---------+--------------------
timestamp | integer | not null default 0
rep=# SELECT distinct trunc(TIMESTAMP 'epoch' + ((floor(timestamp/86400))*86400) *INTERVAL '1 second') as Date_New FROM repdaily limit 1;
date_new
------------
2016-06-26
(1 row)
rep=# select version();
version
--------------------------------------------------------------------------------------------------------------------------
PostgreSQL 8.0.2 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 3.4.2 20041017 (Red Hat 3.4.2-6.fc3), Redshift 1.0.1096
(1 row)
rep=#
2>我尝试在 9.5.4 和 8.0.2 中运行相同的查询:
我不知道如何使它通用,以便我们可以在任何地方运行它。
rep=# \d repdaily
Table "prod.repdaily"
Column | Type | Modifiers
---------------------------+---------+--------------------
timestamp | integer | not null default 0
rep=#
rep=# SELECT distinct trunc(TIMESTAMP 'epoch' + ((floor(timestamp/86400))*86400) *INTERVAL '1 second') as Date_New FROM repdaily limit 1;
ERROR: function trunc(timestamp without time zone) does not exist
LINE 1: SELECT distinct trunc(TIMESTAMP 'epoch' + ((floor(timestamp/...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
rep=#
rep=# select version();
version
----------------------------------------------------------------------------------------------------------
PostgreSQL 9.5.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17), 64-bit
(1 row)
rep=#
rep=# select version();
version
-----------------------------------------------------------------------------------------------------------
PostgreSQL 8.0.2 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17)
(1 row)
rep=#
【问题讨论】:
-
在 Postgres 中是
date_trunc(),而不仅仅是trunc()
标签: postgresql amazon-redshift