In Amazon Redshift I'm looking to convert the current timestamp to have 0 seconds. That is go from this:
2013-12-17 12:27:50
to this:
2013-12-17 12:27:00
I have tried the following:
SELECT dateadd(second, -(date_part(second, getdate())), getdate());
ERROR: function pg_catalog.date_add("unknown", double precision, timestamp without time zone) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
SELECT dateadd(second, -cast(date_part(second, getdate()) as double precision), getdate());
ERROR: function pg_catalog.date_add("unknown", double precision, timestamp without time zone) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
SELECT getdate() - date_part(second, getdate());
ERROR: operator does not exist: timestamp without time zone - double precision
HINT: No operator matches the given name and argument type(s). You may need to add explicit type casts.
I'm probably missing a very simple way of doing this! Does anyone have any suggestions, please?
GETDATE returns the current date and time in the current session time zone (UTC by default). It returns the start date or time of the current statement, even when it is within a transaction block.
An interval is expressed as a combination of the INTERVAL keyword with a numeric quantity and a supported date part, for example INTERVAL '7 days' or INTERVAL '59 minutes' . You can connect several quantities and units to form a more precise interval, for example: INTERVAL '7 days, 3 hours, 59 minutes' .
The default timestamp without time zone (TIMESTAMP) format is YYYY-MM-DD HH:MI:SS. The default timestamp with time zone (TIMESTAMPTZ) format is YYYY-MM-DD HH:MI:SSOF, where OF is the offset from UTC (for example, -8:00.
It's easiest to use the date_trunc()
function, but that will work only while selecting:
SELECT date_trunc('minute', TIMESTAMP '2013-12-17 12:27:00');
You may preprocess data before loading data into the redshift DB, or use intermediary table and then use INSERT INTO...SELECT
statement:
INSERT INTO destination_table (
SELECT date_trunc('minute', date_column), other_columns_here
FROM source_table
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With