Skip site navigation (1) Skip section navigation (2)

Re: Help creating a function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Eduardo Cadena" <ecadenag(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Help creating a function
Date: 2002-10-03 17:12:42
Message-ID: 10300.1033665162@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
"Eduardo Cadena" <ecadenag(at)hotmail(dot)com> writes:
> CREATE FUNCTION month(timestamp) RETURNS date AS '
>   DECLARE
>     fecha ALIAS FOR $1 ;
>     mes int4;
>   BEGIN
>     SELECT INTO mes EXTRACT (MONTH FROM TIMESTAMP (fecha) );
>     RETURN mes;
>   END
> ' LANGUAGE PLPGSQL;

Try just
     SELECT INTO mes EXTRACT (MONTH FROM fecha);

$1 already is a timestamp, and your attempt to do an unnecessary
coercion via function syntax is running into the problem that
TIMESTAMP(...) is a reserved syntax per SQL.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Doug SilverDate: 2002-10-03 17:32:29
Subject: Re: inserting data that contains / or \
Previous:From: Patrick HatcherDate: 2002-10-03 17:02:37
Subject: inserting data that contains / or \

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group