Functions and triggers can anyone help

From: RobertD(dot)Stewart(at)mail(dot)state(dot)ky(dot)us
To: pgsql-general(at)postgresql(dot)org
Subject: Functions and triggers can anyone help
Date: 2003-02-05 12:26:55
Message-ID: 098C0DC713F9D311B2FB00508B95327605971738@agency2.state.ky.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm having a problem with setting up a function and a trigger for one of me
tables. I have just started using Postgresql and I'm trying to convert my
Oracle database over to see how it runs.

Here is my Oracle Functions

Create Or Replace FUNCTION SET_USERNAME

( eventtype IN varchar2,

message IN varchar2)

RETURN varchar2 IS

username varchar2(30);

pos1 number(7);

pos2 number(7);

BEGIN

if eventtype = 'AUDIT_SUCCESS' then

pos1 := instr(message, 'User Name:') + 10;

pos2 := instr(message, 'Domain');

return substr(message, pos1, pos2-pos1);

elsif eventtype = 'AUDIT_FAILURE' then

pos1 := instr(message, 'User Name:') + 10;

pos2 := instr(message, 'Domain:');

if (pos1 = 0 or pos2 = 0) then

pos1 := instr(message, 'Account Name:') + 13;

pos2 := instr(message, 'Target Domain:');

end if;

return substr(message, pos1, pos2-pos1);

end if;

return '' ;

EXCEPTION

WHEN others THEN

return '' ;

END;

And Here is my Postgresql function but when I try to set the trigger it says
it can't find the function (it does not exist)

CREATE FUNCTION set_username4(varchar, varchar) RETURNS opaque AS '

DECLARE

eventtype varchar;

message varchar;

username varchar(30);

pos1 number(7);

pos2 number(7);

BEGIN

if eventtype = ''AUDIT_SUCCESS'' then

pos1 := instr(message, ''User Name:'') + 10;

pos2 := instr(message, ''Domain'');

return substr(message, pos1, pos2-pos1);

elsif eventtype = ''AUDIT_FAILURE'' then

pos1 := instr(message, ''User Name:'') + 10;

pos2 := instr(message, ''Domain:'');

if (pos1 = 0 or pos2 = 0) then

pos1 := instr(message, ''Account Name:'') + 13;

pos2 := instr(message, ''Target Domain:'');

end if;

return substr(message, pos1, pos2-pos1);

end if;

return '' ;

EXCEPTION

WHEN others THEN

return '' ;

END;

' LANGUAGE 'plpgsql';

Robert Stewart

Division of Communications

Office of Infrastructure Services

Governors Office for Technology

Commonwealth of Kentucky

work: 502 564 4287

cell: 502 330 5991

pager 877 543 0473

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Vilson farias 2003-02-05 12:40:31 Temporary and permanent tables with same name
Previous Message roverr 2003-02-05 11:46:35 Question: unique on multiple columns