From: | Thorsten Kraus <TK-Spam(at)gmx(dot)de> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Stored procedure |
Date: | 2007-05-03 14:59:59 |
Message-ID: | 4639F8EF.70300@gmx.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi NG,
I want to write a stored procedure which creates a table in my
PostgreSQL database. The procedure has one input parameter: the table name.
Here is my first try, but that does not work:
--------------------------------------------------------------------------------------------------
CREATE OR REPLACE FUNCTION create_geom_table(text) RETURNS void AS $$
DECLARE
--table_name TEXT;
BEGIN
---------------------------------------
CREATE TABLE table_name
(
id integer,
"time" timestamp without time zone,
geom geometry,
CONSTRAINT enforce_dims_geom CHECK (ndims(geom) = 2),
CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) =
'MULTIPOLYGON'::text OR geom IS NULL),
CONSTRAINT enforce_srid_geom CHECK (srid(geom) = -1)
)
WITHOUT OIDS;
ALTER TABLE table_name OWNER TO "admin";
CREATE INDEX geo_index ON table_name USING gist(geom);
---------------------------------------
ALTER FUNCTION create_geom_table(table_name) OWNER TO "admin";
END;
$$ LANGUAGE plpgsql;
--------------------------------------------------------------------------------------------------
Can someone tell me what's wrong with this and what I have to change?
Regards,
Thorsten
From | Date | Subject | |
---|---|---|---|
Next Message | Alban Hertroys | 2007-05-03 15:02:38 | Re: Update violating constraint |
Previous Message | Tom Lane | 2007-05-03 14:43:28 | Re: psql access of user's environmental variables |