pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedTable-name as parameter to plpgsql
2+ messages / 2 participants
[nested] [flat]
* Table-name as parameter to plpgsql
@ 2007-07-30 21:35 Andreas Joseph Krogh <andreak@officenet.no>
2007-07-31 00:34 ` Re: Table-name as parameter to plpgsql Milen A. Radev <milen@radev.net>
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Joseph Krogh @ 2007-07-30 21:35 UTC (permalink / raw)
To: pgsql-sql
The following function failes to compile:
CREATE OR REPLACE FUNCTION test_func(p_table_name VARCHAR) RETURNS VOID AS $$
BEGIN
INSERT INTO p_table_name(some_field) VALUES('some_value');
END;
$$ LANGUAGE plpgsql;
Gives:
ERROR: syntax error at or near "$1"
LINE 1: INSERT INTO $1 (some_field) VALUES('some_value')
Any hints on how to use function-parameters as table-names like I'm trying to
above?
--
Andreas Joseph Krogh <andreak@officenet.no>
Senior Software Developer / Manager
------------------------+---------------------------------------------+
OfficeNet AS | The most difficult thing in the world is to |
Karenslyst Allé 11 | know how to do a thing and to watch |
PO. Box 529 Skøyen | somebody else doing it wrong, without |
0214 Oslo | comment. |
NORWAY | |
Tlf: +47 24 15 38 90 | |
Fax: +47 24 15 38 91 | |
Mobile: +47 909 56 963 | |
------------------------+---------------------------------------------+
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Table-name as parameter to plpgsql
2007-07-30 21:35 Table-name as parameter to plpgsql Andreas Joseph Krogh <andreak@officenet.no>
@ 2007-07-31 00:34 ` Milen A. Radev <milen@radev.net>
0 siblings, 0 replies; 2+ messages in thread
From: Milen A. Radev @ 2007-07-31 00:34 UTC (permalink / raw)
To: pgsql-sql
Andreas Joseph Krogh написа:
> The following function failes to compile:
>
> CREATE OR REPLACE FUNCTION test_func(p_table_name VARCHAR) RETURNS VOID AS $$
> BEGIN
> INSERT INTO p_table_name(some_field) VALUES('some_value');
> END;
> $$ LANGUAGE plpgsql;
>
> Gives:
> ERROR: syntax error at or near "$1"
> LINE 1: INSERT INTO $1 (some_field) VALUES('some_value')
>
> Any hints on how to use function-parameters as table-names like I'm trying to
> above?
>
Use EXECUTE
(http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-D...).
--
Milen A. Radev
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2007-07-31 00:34 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-07-30 21:35 Table-name as parameter to plpgsql Andreas Joseph Krogh <andreak@officenet.no>
2007-07-31 00:34 ` Milen A. Radev <milen@radev.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox