Re: Help with plpgsql - subst variable value

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Alexander Bodnar <bodnar(at)malva(dot)com(dot)ua>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Help with plpgsql - subst variable value
Date: 2001-02-22 19:17:43
Message-ID: Pine.BSF.4.21.0102221115100.13173-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


In 7.1, you should be able to use EXECUTE to execute an sql string.
You can basically build the create sequence string and use
execute to run it. As a stripped down version, I did something like:

CREATE FUNCTION CreateObject(varchar(600)) RETURNS int4 AS '
DECLARE
ObjectSeqName text;
ObjectID ALIAS FOR $1;
BEGIN
ObjectSeqName := ''ObjectLog'' || ObjectID || ''_Seq'';
EXECUTE ''CREATE SEQUENCE '' || ObjectSeqName || '' start 1 increment 1 maxvalue 2147483647 minvalue 1 cache 1 CYCLE;'';
return 1;
END;
' LANGUAGE 'plpgsql';

When I executed it it created the sequence with the name I passed in.

On Thu, 22 Feb 2001, Alexander Bodnar wrote:

> Hi all.
>
> This my code snapshot:
>
> CREATE FUNCTION CreateObject(varchar(600)) RETURNS int4 AS '
> DECLARE
> . . .
> ObjectSeqName text;
> BEGIN
> . . ..
> ObjectSeqName := ''ObjectLog'' || ObjectID || ''_Seq'';
> CREATE SEQUENCE ObjectSeqName start 1 increment 1 maxvalue 2147483647
> minvalue 1 cache 1 CYCLE;
> . . .
> END IF;
> RETURN ObjectID;
> END;
> ' LANGUAGE 'plpgsql';
>
> When I run this function I got
> ERROR: parser: parse error at or near "$1"
>
> So how can get value of ObjectSeqName in sequence/table/etc. name?
>
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message newsreader 2001-02-22 19:20:27 Re: PostgreSQL 7.1 Linux Installation
Previous Message Paulo Parola 2001-02-22 19:07:06 PostgreSQL 7.1 Linux Installation