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: [EMAIL PROTECTED] -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql