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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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