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: Creation of a table with dynamic name from inside a pgpsql function
Date: Tue, 28 May 2002 17:53:41 +0200
Message-ID: <1020528175341.ZM17959@sirari.TechFak.Uni-Bielefeld.DE> (raw)

Hi,

i have tried to create a table with a name specified by a calling parameter of
a pgsql function. Something like this:
CREATE FUNCTION test (varchar) RETURNS TEXT AS '
DECLARE
	table_name ALIAS FOR $1;
	query_string varchar;

BEGIN
query_string:= ''CREATE TABLE temp1 AS SELECT * FROM ''||
quote_ident(table_name) || '' WHERE (hsp_rank=1 AND hsp_evalue<=0.001)'';
RAISE NOTICE ''Query: %'',query_string;
EXECUTE query_string;
RETURN table_name;
END;
' LANGUAGE 'plpgsql';

with the following result:

prod2_db=# select test('blasthits_obj_174_q122_db123');
NOTICE:  Query: CREATE TABLE temp1 AS SELECT * FROM
blasthits_obj_174_q122_db123 WHERE (hsp_rank=1 AND hsp_evalue<=0.001)
ERROR:  EXECUTE of SELECT ... INTO is not implemented yet
prod2_db=#

i read in the docs, that an SELECT INTO is not fully supported, but how can i
solve this problem ? Any idea or workaround ?

Regards
Michael Beckstette



view thread (2+ messages)  latest in thread

Message-ID: <1020528175341.ZM17959@sirari.TechFak.Uni-Bielefeld.DE>
Permalink:  ../1020528175341.ZM17959@sirari.TechFak.Uni-Bielefeld.DE/
Also on:    postgresql.org/message-id/1020528175341.ZM17959@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 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-sql@postgresql.org
  Cc: mbeckste@TechFak.Uni-Bielefeld.DE
  Subject: Re: Creation of a table with dynamic name from inside a pgpsql function
  In-Reply-To: <1020528175341.ZM17959@sirari.TechFak.Uni-Bielefeld.DE>
  References: <1020528175341.ZM17959@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