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

Help creating a function

From: "Eduardo Cadena" <ecadenag(at)hotmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Help creating a function
Date: 2002-10-03 15:28:25
Message-ID: F270iAXAYvDZOF210Tm0000dcc3@hotmail.com (view raw or flat)
Thread:
Lists: pgsql-novice

Hi


I'm migrating an apllicattion taht use MS-Access to postgreSQL, many of the 
SQL statements contains simple functions
like month(), date(), year(),  and so on , I don't want   to modify all the 
statements (are about 200), so i'm creating functions in my postgres db with 
this names and functionality, but i get errors.

For example, the function month

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;

When executed results in :

SCE=# SELECT  month('2002-2-3');
NOTICE:  Error occurred while executing PL/pgSQL function month
NOTICE:  line 7 at select into variables
ERROR:  parser: parse error at or near "$1"

I don't known what i'm doing wrong so i need your help.


Thanks

Eduardo Cadena

_________________________________________________________________
Únase al mayor servicio mundial de correo electrónico: 
http://www.hotmail.com/es


pgsql-novice by date

Next:From: Eduardo CadenaDate: 2002-10-03 16:11:10
Subject: Help creating a function
Previous:From: Zeno DavatzDate: 2002-10-02 14:34:12
Subject: pg_restore authentication failure

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