sqlamazon-redshift

extract time from now() in amazon redshift


I am trying to extract the time part only (excluding milliseconds) from the date-time string in amazon redshift.

I used:

Select now()::time;

But it is giving me error.

Error running query: Specified types or functions (one per INFO message) not supported on Redshift tables.

Any help would be highly appreciated.


Solution

  • I'm less sure about the error, but I agree with Jon Scott's comment, the following query runs fine without any error.

    Select now()::time;
    

    It outputs something like:

    09:23:49.697401

    It contains time with 6 digits after seconds.

    If you just add time parameter up to, how many digits your need after seconds like below. Here its 0.

    Select now()::time(0);
    

    This will output:

    09:23:49

    If you do;

    Select now()::time(1);
    

    This will output:

    09:23:49.6

    Hope it answers your question.