Re: How to creat tables using record ID in for loop - Mailing list pgsql-sql

From Yura Gal
Subject Re: How to creat tables using record ID in for loop
Date
Msg-id 3b6c69d80808070329t2a471b43v4c14be7026a517bd@mail.gmail.com
Whole thread Raw
In response to Re: How to creat tables using record ID in for loop  ("Yura Gal" <yuragal@gmail.com>)
List 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
$$
DECLAREstid INTEGER;q TEXT;
BEGINFOR 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@gmail.com


pgsql-sql by date:

Previous
From: "Yura Gal"
Date:
Subject: Re: How to creat tables using record ID in for loop
Next
From: felix@crowfix.com
Date:
Subject: DELETE with JOIN