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 re
The function to treate tables is:
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: %'
On miư, 2008-08-06 at 18:52 +, CHUNRIMACHUNRIMA wrote:
> "96784002";"mylocation #1"
> "02385067";"mylocation #2"
> "01734056";"mylocation #3"
...
> 3. What I want to do is to create tables with staid from mytest table
> using for loop.
...
> +++Example+++
>
> CREATE TABLE s06784000 (
> st
1. I have created the first table and inserted records as below
CREATE TABLE mytest (
staid varchar(20),
kdesc varchar(50) -- description of gage station
)
WITHOUT OIDS;
INSERT INTO mytest VALUES ('96784002', 'mylocation #1');
INSERT INTO mytest VALUES ('02385067'