Re: functions with plpgsql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



> CREATE FUNCTION "next_id"(character varying) RETURNS integer AS '
> DECLARE
>     tabelle ALIAS FOR $1;
> BEGIN
>     SELECT MAX(id)+1 FROM tabelle;
> END;
> ' LANGUAGE 'plpgsql'
>
> query:
>
> SELECT next_id(logs);
>
> error:
>
> PostgreSQL meldet: ERROR: parser: parse error at or near "$1"
>
> Can anybody help me?


I do not think you can evaluate a declared vairable as a table name in the 
SELECT statement.

I don't think you really need to do this though.  If you have the table name 
already.

why go:

SELECT next_id(logs);

And write this functios instead of:

SELECT MAX(id) + 1 FROM logs;


??


Andy


[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux