|
Home > Archive > PostgreSQL Discussion > March 2006 > Is this possible.
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Harvey, Allan AC 2006-03-29, 8:26 pm |
| Hi all,
Can sombody please help me realise a function, the intent as described by...
-- Function to create the table for a new point
CREATE OR REPLACE FUNCTION make_table( varchar ) RETURNS VARCHAR AS '
CREATE TABLE $1(
parameter varchar(8) NOT NULL,
value float NOT NULL,
dt timestamp NOT NULL
);
CREATE INDEX $1_dtindex ON $1( dt );
SELECT $1;
' LANGUAGE SQL;
I'm using 7.4.5.
Thanks
Allan
The material contained in this email may be confidential, privileged or copyrighted. If you are not the intended recipient, use, disclosure or copying of this information is prohibited. If you have received this document in error, please advise the sender
and delete the document. Neither OneSteel nor the sender accept responsibility for any viruses contained in this email or any attachments.
---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
choose an index scan if your joining column's datatypes do not
match
| |
| Klint Gore 2006-03-29, 8:26 pm |
| On Thu, 30 Mar 2006 10:45:20 +1100, "Harvey, Allan AC" <HarveyA@OneSteel.com> wrote:
> Hi all,
>
> Can sombody please help me realise a function, the intent as described by...
>
> -- Function to create the table for a new point
>
> CREATE OR REPLACE FUNCTION make_table( varchar ) RETURNS VARCHAR AS '
> CREATE TABLE $1(
> parameter varchar(8) NOT NULL,
> value float NOT NULL,
> dt timestamp NOT NULL
> );
execute ''create table ''||quote_ident($1)|
|'' (...)'';
> CREATE INDEX $1_dtindex ON $1( dt );
execute ''create index ''||quote_ident($1)|
|''_dtindex ...'';
> SELECT $1;
return $1;
> ' LANGUAGE SQL;
' language plpgsql;
quote_ident function should help with sql insertion attack.
klint.
+---------------------------------------+-----------------+
: Klint Gore : "Non rhyming :
: EMail : kg@kgb.une.edu.au : slang - the :
: Snail : A.B.R.I. : possibilities :
: Mail University of New England : are useless" :
: Armidale NSW 2351 Australia : L.J.J. :
: Fax : +61 2 6772 5376 : :
+---------------------------------------+-----------------+
---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?
http://www.postgresql.org/docs/faq
|
|
|
|
|