Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Location
    Portugal
    Posts
    21

    Unanswered: Pl/pgsql trigger returning values??

    Hi,

    Am ewbie to postgres...could appreciate some help..
    I created the following function and trigger that simply breaks a date down into the day, month, year:

    CREATE FUNCTION pg_fct_person_insert4 () RETURNS TRIGGER AS '
    DECLARE

    BEGIN
    NEW.GEBTT := TO_CHAR(NEW.GEBDAT, ''DD'');
    NEW.GEBMM := TO_CHAR(NEW.GEBDAT, ''MM'');
    NEW.GEBJJJJ := TO_CHAR(NEW.GEBDAT, ''YYYY'');

    RETURN NEW;
    END;
    ' LANGUAGE 'plpgsql';

    create trigger trigperson before insert on tbl0100person
    for each row execute procedure pg_fct_person_insert4();

    but I receive the following error:
    WARNING: at END of toplevel PL block
    ERROR: control reaches end of trigger procedure without RETURN

    How so, if I do return the NEW??

    Thanks a ton

  2. #2
    Join Date
    Jan 2003
    Location
    Midwest
    Posts
    138
    you don't seem to be passing the function a value?

  3. #3
    Join Date
    Feb 2003
    Location
    Portugal
    Posts
    21
    I don´t pass any value because there is no need for this. i have looked in all the examples in the book "Practival postrgresql" and the structure seems to be the same as mine, with the diference that they work and mine does not.

    In chapter 11:
    'A trigger function should be defined as accepting no arguments, and returns a value of the special opaque data type..'

    Got any clues?

  4. #4
    Join Date
    Feb 2003
    Location
    Portugal
    Posts
    21

    Smile resolved!

    Got the problem resolved...I had an old trigger defined with another function as well. So my current trigger and function is ok, the error was related to an old trigger also running on the table.

    Thanks just the same!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •