Re: functions with plpgsql

From: "Andrew J(dot) Kopciuch" <akopciuch(at)olympusproject(dot)org>
To: "Bernd Hoffmann" <info(at)unixserver(dot)info>, <pgsql-php(at)postgresql(dot)org>
Subject: Re: functions with plpgsql
Date: 2003-08-10 00:04:10
Message-ID: 200308091804.10545.akopciuch@olympusproject.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Bernd Hoffmann 2003-08-10 00:33:36 Re: functions with plpgsql
Previous Message Bernd Hoffmann 2003-08-09 20:18:38 functions with plpgsql