0

I have a table named employee with 5 columns. One column is named emp_empdt it's type is timestamp .

I need to get hour value of emp_empdt of every record in the employee table.

I know that, we can get hour by using like

SELECT extract(hour from timestamp '2015-05-02 20:05:12'); 

This is an static query. But now i need to get timestamp value from employee table.

I used like:

SELECT h1 
from (
   select extract(hour from timestamp emp.emp_empdt) as h1 
   from employee emp
);

1 Answers1

3

The timestamp keyword is not required:

select extract(hour from emp_empdt) as h1 
from employee emp

The expression timestamp '2015-05-02 20:05:12' is an ANSI SQL timestamp literal and the keyword timestamp is only required for a literal like that. This is necessary to distinguish such an expression from a character literal ('2015-05-02 20:05:12').

  • @a_horse_with_no_name : Not working while executing above query its say : HINT: No function matches the given name and argument types. You might need to add explicit type casts. – Bhargav Patel Aug 10 '17 at 09:04