plpgsql Functions: Text Variables - Mailing list pgsql-novice

From Carel Combrink
Subject plpgsql Functions: Text Variables
Date
Msg-id 20100603154742.lnwgcxuy0ok8kck0@student.up.ac.za
Whole thread Raw
Responses Re: plpgsql Functions: Text Variables
List pgsql-novice
Hi,

I want to create a function in plpgsql that must execute a INSERT
query on the database. The problem comes in I want to create the query
inside the function. Look at the following:

CREATE OR REPLACE FUNCTION Test_Function(integer) RETURNS VOID
AS $$
DECLARE
   table_name text := 'My_Table_Name';
BEGIN
   INSERT INTO "table_name" VALUES ($1);
END
$$ LANGUAGE plpgsql;

When I try to create the function I get the following response from Postgres:
ERROR:  syntax error at or near "$1"
LINE 1: INSERT INTO  $1  VALUES ( $2 )
                      ^
QUERY:  INSERT INTO  $1  VALUES ( $2 )
CONTEXT:  SQL statement in PL/PgSQL function "test_function" near line 4

What am I missing? Is it possible to do what I want to do? And if so
how should I do it.

Note: The function is only to show what the problem is, actual
function should look a lot different.

Any help will be appreciated
Thank you
--
Carel Combrink
s25291930@tuks.co.za

This message and attachments are subject to a disclaimer. Please refer
to www.it.up.ac.za/documentation/governance/disclaimer/ for full
details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule
onderhewig. Volledige besonderhede is by
www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.



pgsql-novice by date:

Previous
From: machielr@rdc.co.za
Date:
Subject: slony config error
Next
From: Tom Lane
Date:
Subject: Re: slony config error