function to update different tables

From: "Lars Eckberg" <le(at)eckbergconsulting(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: function to update different tables
Date: 2004-11-03 11:42:32
Message-ID: 20041103112919.M58332@eckbergconsulting.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hey all,

Newbie question:

I'm trying to create a function, where the first parameter will be the
tablename to update. I have tried to escape $1 in every way I can think of,
but with no luck. I get an error when trying to create the function.

ERROR: parser: parse error at or near "$1" at character 11

Here is the function:

CREATE FUNCTION reserve_ports(text,smallint,text,text,int) RETURNS smallint AS
'
UPDATE $1
SET status = \'reserved\', vlan_uid = $2, c_uid = $3
WHERE status = \'free\' AND oid IN (SELECT oid FROM $1 WHERE status =
\'free\' AND module_type ILIKE $4 ORDER BY id LIMIT $5);
SELECT 1;
' LANGUAGE SQL;

I have looked at the manual but i cant seem to find anything covering this.
Do i have to use another approach??

Any examples or hints will be appreciated greatly. =)

Cheers,
--Lars

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Raphael Bauduin 2004-11-03 13:17:59 building a row with a plpgsql function
Previous Message Kjetil Haaland 2004-11-03 09:29:17 c extension