postgresql - PL/pgSQL , How to make a function using Raise notices and export the messages from the console to a text file from the Code -


i have make update function have multiple conditions

begin   open cur3 execute('select id_organigramme ( select distinct  id_personne,id_organigramme,idfax  requpdate     id_personne= ' || variableidpersonne || ' , idfax  null)     a.id_organigramme not in (select distinct   id_organigramme      requpdate id_personne= ' ||variableidpersonne || ' , idfax     not null , a.id_personne=requpdate.id_personne )  ');   loop     fetch cur3 variableidorganigrammefax;      if not found       --message here !!!       --raise notice 'hello word!'          exit;     end if; 

i have show messages if condition exists found out can raise notice/info ... statement, have make auto export of messages text file when function finishes. possible? otherwise can use make it.

i use pgadminiii client.

what logging options depends entirely on client configuration. rather using raise notice suggest use notify \ listen framework. basically, in function issue notice channel of choosing (can string) , in client listen same channel, logging messages come in. how listening , logging works depends on client.

the code show can use improvements.

first of all, query incredibly convoluted version of:

select distinct id_organigramme requpdate id_personne = variableidpersonne   , idfax null; 

secondly, not need dynamic query, can variable substitution. assuming id_personne not string, simple stated above, otherwise use quote_literal(variableidpersonne).

lastly, unless there parts of function not shown require cursor, can do:

for variableidorganigrammefax in [query above] loop   ... -- processing here end loop;  if not found  -- loop above did not iterate because no records returned   select pg_notify('logmyfunction', format('%s: no records found', variableidpersonne)); end if;

the pg_notify() function wrapper around notify command makes possible pass variable strings.

before call function, should issue command listen logmyfunction session receive notifications channel.


Comments

Popular posts from this blog

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

javascript - Create websocket without connecting -

android - Linear layout children not scrolling -