Re: functions with plpgsql - Mailing list pgsql-php

From Andrew J. Kopciuch
Subject Re: functions with plpgsql
Date
Msg-id 200308091804.10545.akopciuch@olympusproject.org
Whole thread Raw
In response to functions with plpgsql  ("Bernd Hoffmann" <info@unixserver.info>)
List pgsql-php
> 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

pgsql-php by date:

Previous
From: "Bernd Hoffmann"
Date:
Subject: functions with plpgsql
Next
From: "Bernd Hoffmann"
Date:
Subject: Re: functions with plpgsql