pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew J. Kopciuch <akopciuch@olympusproject.org>
To: Bernd Hoffmann <info@unixserver.info>
To: pgsql-php@postgresql.org
Subject: Re: functions with plpgsql
Date: Sat, 9 Aug 2003 18:04:10 -0600
Message-ID: <200308091804.10545.akopciuch@olympusproject.org> (raw)
In-Reply-To: <01b101c35eb3$6e75b2b0$3214a8c0@server>
References: <01b101c35eb3$6e75b2b0$3214a8c0@server>


> 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



view thread (4+ messages)  latest in thread

Message-ID: <200308091804.10545.akopciuch@olympusproject.org>
Permalink:  ../200308091804.10545.akopciuch@olympusproject.org/
Also on:    postgresql.org/message-id/200308091804.10545.akopciuch@olympusproject.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: akopciuch@olympusproject.org, info@unixserver.info
  Subject: Re: functions with plpgsql
  In-Reply-To: <200308091804.10545.akopciuch@olympusproject.org>
  References: <01b101c35eb3$6e75b2b0$3214a8c0@server> <200308091804.10545.akopciuch@olympusproject.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox