Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group