pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Beckstette <mbeckste@TechFak.Uni-Bielefeld.DE>
To: pgsql-sql@postgresql.org
Subject: dynamic table names, determined by calling parameter
Date: Tue, 28 May 2002 16:43:03 +0200
Message-ID: <1020528164303.ZM17839@sirari.TechFak.Uni-Bielefeld.DE> (raw)

Hi,

sorry, when this is a silly question, but i wonder why the following pl/pgsql
functions works:

CREATE FUNCTION test (text) RETURNS TEXT AS '
DECLARE
	table_name ALIAS FOR $1;

BEGIN
	--   test_table is an existing table
CREATE TEMPORARY TABLE temp1 AS SELECT * FROM test_table WHERE (hsp_rank=1 AND
hsp_evalue<=evalue_cutoff);
RETURN table_name;
END;
' LANGUAGE 'plpgsql';



and this one with the table name specified by the calling parameter not:

CREATE FUNCTION test (text) RETURNS TEXT AS '
DECLARE
	table_name ALIAS FOR $1;

BEGIN

CREATE TEMPORARY TABLE temp1 AS SELECT * FROM table_name WHERE (hsp_rank=1 AND
hsp_evalue<=evalue_cutoff);
RETURN table_name;
END;
' LANGUAGE 'plpgsql';


Result:
prod2_db=#SELECT test('test_table');
ERROR:  parser: parse error at or near "$1"

Any idea ?

Regards
Michael Beckstette



view thread (2+ messages)

Message-ID: <1020528164303.ZM17839@sirari.TechFak.Uni-Bielefeld.DE>
Permalink:  ../1020528164303.ZM17839@sirari.TechFak.Uni-Bielefeld.DE/
Also on:    postgresql.org/message-id/1020528164303.ZM17839@sirari.TechFak.Uni-Bielefeld.DE

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mbeckste@TechFak.Uni-Bielefeld.DE
  Subject: Re: dynamic table names, determined by calling parameter
  In-Reply-To: <1020528164303.ZM17839@sirari.TechFak.Uni-Bielefeld.DE>

* 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