plpgsql dynamic record access

Поиск
Список
Период
Сортировка
От Ganesh
Тема plpgsql dynamic record access
Дата
Msg-id 20050601065425.46B8937DF0@sitemail.everyone.net
обсуждение исходный текст
Список pgsql-sql
<font size="2" style="font-family: arial,helvetica,sans-serif;">Hello, <br />        I have searched everywere  for a
solutionpls help me. I am building a trigger which would keep track of every modification to some table. here i am
generlisingthe function. the following is the code in plpgsql. <br />  <br />  <br /> --/* function for giving the
fieldattributes of a given table */ <br /> CREATE FUNCTION get_fld_name(text) RETURNS _varchar AS ' <br /> DECLARE <br
/>   out_fld text[20] := array[''name'',''no'']; <br />  <br /> BEGIN <br />   RETURN out_fld; <br /> END; <br /> '
LANGUAGE'plpgsql'; <br />  <br /> --/** function for recording the changes  **/ <br />  <br /> CREATE FUNCTION
my_func_test()RETURNS OPAQUE AS ' <br /> DECLARE <br />  <br />  flds text[20]; <br />  fldname text; <br />  <br />
 ofldtext; <br />  nfld text; <br />  <br /> BEGIN <br />  <br /> flds := (SELECT *  from  get_fld_name(TG_RELNAME));
<br/>   IF TG_OP=''INSERT'' THEN <br />       ofld=nfld; <br />   END IF; <br />   FOR i IN 1..20 loop <br />     IF
flds[i]<> ''NULL'' THEN <br />        fldname := flds[i]; <br />  <br /><span style="background-color: rgb(255,
255,255); color: rgb(0, 0, 153);">--/**************** Here is the problem ****************/ </span><br
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span style="background-color: rgb(255, 255,
255);color: rgb(0, 0, 153);"> </span><br style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);">      ofld := OLD.fldname;  -- this should return
Old'svalue </span><br style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);">      nfld := NEW.fldname;  -- this should return
New'svalue </span><br style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);"> </span><br style="background-color: rgb(255, 255,
255);color: rgb(0, 0, 153);" /><span style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 153);">--/****I want
toget he value from OLD.name or OLD.No *******/ </span><br style="background-color: rgb(255, 255, 255); color: rgb(0,
0,153);" /><span style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 153);"> </span><br
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span style="background-color: rgb(255, 255,
255);color: rgb(0, 0, 153);">--/*********************************************************** </span><br
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span style="background-color: rgb(255, 255,
255);color: rgb(0, 0, 153);"> </span><br style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);">    Is there any way to concatnate the 2 Objects
[(OLD)and (Fldname) ] so that fldname would be converted to the value but the object OLD remains same. </span><br
style="background-color:rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span style="background-color: rgb(255, 255,
255);color: rgb(0, 0, 153);"> </span><br style="background-color: rgb(255, 255, 255); color: rgb(0, 0, 153);" /><span
style="background-color:rgb(255, 255, 255); color: rgb(0, 0,
153);">***********************************************************/</span><br/>  <br />          ofld := old_data[i];
<br/>          nfld := new_data[i]; <br />  <br />     INSERT INTO Audit_table values
(5,TG_RELNAME,''now'',TG_OP,fldname,ofld,nfld,current_user);<br />  <br />          RAISE NOTICE ''ss : % '',fldname;
<br/>    RAISE NOTICE ''ofldname : % '',ofld; <br />    RAISE NOTICE ''nfldname : % '',nfld; <br />  <br />     END IF;
<br/>   END LOOP; <br />  RETURN NEW; <br /> END; <br />   ' LANGUAGE 'plpgsql'; <br />  <br />  <br />  <br /> CREATE
TRIGGERtest_trig AFTER UPDATE ON test <br /> FOR EACH ROW EXECUTE PROCEDURE my_func_test(); <br />  <br />  <br />  <br
/>Please Help me.. <br />  <br /> Thanks ,<br /> <br />R.Ganesh<br /><br />mail to :  ganesh@volleyball.com<br /><br
/></font><br/> <br /><hr />Get your FREE email @ http://Volleyball.Com - Get everything for volleyball @
http://Shop.Volleyball.Com- Post a message @ http://Forum.Volleyball.Com<br /> 

В списке pgsql-sql по дате отправления:

Предыдущее
От: Mark Dilger
Дата:
Сообщение: Re: Sum() rows
Следующее
От: lucas@presserv.org
Дата:
Сообщение: Re: Sum() rows