Re: How to creat tables using record ID in for loop

From: "Yura Gal" <yuragal(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: How to creat tables using record ID in for loop
Date: 2008-08-07 10:29:19
Message-ID: 3b6c69d80808070329t2a471b43v4c14be7026a517bd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Oh, I checked the function. There are some syntax errors. Right code
listed below:

CREATE OR REPLACE FUNCTION cr_tbls_by_staid() RETURNS INTEGER AS
$$
DECLARE
stid INTEGER;
q TEXT;
BEGIN
FOR stid IN SELECT staid FROM mytest LOOP
q:= 'CREATE TABLE "s' || staid || '" (staid varchar(50), val real,
dt date);';
RAISE NOTICE 'query is: %', q; --for debug
EXECUTE q;
END LOOP;
RETURN 1;
END;
$$ LANGUAGE plpgsql;

Also I forget to change first column definition in last CREATE TABLE
query. Edited variant is, for sure:
CREATE TABLE sta_descs (staid INTEGER, val real, dt date) WITHOUT OIDS;

--
Best regards. Yuri.
mailto: yuragal(at)gmail(dot)com

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message felix 2008-08-07 16:14:49 DELETE with JOIN
Previous Message Yura Gal 2008-08-07 06:50:34 Re: How to creat tables using record ID in for loop