简体   繁体   中英

current_timestamp redshift

When I select current_timestamp from redshift, I am getting a list of values instead of one value.

Here is my SQL query

select current_timestamp 
from stg.table;

Does anybody know why I am getting a list of values instead a single value?

This is your query:

select current_timestamp from stg.table

This produces as many rows as there are in table stg.table (since that's the from clause), with a single column that always contains the current date/time on each row. On the other hand, if the table contains no row, the query returns no rows.

If you want just one row, use a scalar subquery without a from clause:

select current_timestamp as my_timestamp

You will receive a row for each row in stg.table. According to the RedShift docs you should be using GETDATE() or SYSDATE() instead. Perhaps you want, eg:

select GETDATE() as my_timestamp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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