[CLUE-Tech] postgres function

Sean LeBlanc seanleblanc at attbi.com
Sun Jun 9 11:42:50 MDT 2002


On 06-09 13:09, Jason Friedman wrote:
> I want to write a function which accepts a timestamp and returns the 
> date portion only.
> 
> I've tried:
> 
> CREATE FUNCTION extract_day(timestamp)
> RETURNS date
> AS 'SELECT DATE_TRUNC('day', $1);'
> LANGUAGE 'sql';
> 
> but get a ERROR:  parser: parse error at or near "day"
> 
> Whereas:
> 
> select date_trunc('day',current_timestamp);
> -[ RECORD 1 ]----------------------
> date_trunc | 2002-06-09 00:00:00+00

Try this:

create function extract_day(timestamp) 
returns timestamp 
as 'select date_trunc(\'day\', $1);'
language 'sql';

You need to escape your tickmarks('). Also it wanted to return it as a
timestamp since apparently date_trunc returns timestamp?  The above compiles
- not sure if it actually works as you want, though.

-- 
Sean LeBlanc:seanleblanc at attbi.com Yahoo:seanleblancathome 
ICQ:138565743 MSN:seanleblancathome AIM:sleblancathome 
Children have neither past nor future - they rejoice in the present. 




More information about the clue-tech mailing list