Getting closer with functions, but... - Mailing list pgsql-general

From Scott Holmes
Subject Getting closer with functions, but...
Date
Msg-id 200007130358.UAA15337@scotts.mynetwork.net
Whole thread Raw
Responses Re: Getting closer with functions, but...
Re: Getting closer with functions, but...
List pgsql-general
This function works but is not selective enough.  The tg_argv[] are pointers
to the arguments passed.  And they do work correctly.

CREATE FUNCTION del_stxnoted () RETURNS opaque AS '
declare
  fname text;
  rkey text;
  BEGIN
    fname := tg_argv[0];
    rkey := ''old.'' || tg_argv[1];
    delete from stxnoted where record_key = old.wher;
    return old;
  END;'
LANGUAGE 'plpgsql';

What I need can be accomplished with a rather massive if/then series:

if fname = "location" then
  delete from stxnoted where filename = "location" and record_key = old.wher;
end if

if fname = "events" then
  delete from stxnoted where filename = "events" and record_key = old.evntnmbr;
end if

... ( maybe 100 different tables )...

It seems the sql statement needs old.field or new.field to provide a value.
Unfortunately, my first value, fname, is not a field value but a table name
and my second value may have one of several field names.

Is there a syntax that will allow me to build an sql statement for use in
theis funcation (ie delete from stxnoted where filename = fname and record_key
= rkey).

Thanks, Scott




pgsql-general by date:

Previous
From: Joseph Shraibman
Date:
Subject: Re: select for update not locking properly.
Next
From: Tom Lane
Date:
Subject: Re: Getting closer with functions, but...