Re: trigger functions broken?

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: trigger functions broken?
Date: 2008-10-08 19:51:48
Message-ID: 20081008195148.GE4164@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

A. Kretschmer wrote:
> am Wed, dem 08.10.2008, um 14:29:23 -0400 mailte Alvaro Herrera folgendes:
> > Hi,
> >
> > Trigger functions are supposed to be able to be called only as triggers,
> > but apparently the check is not working in CVS HEAD:
> >
> > alvherre=# create or replace function foo () returns trigger as $$ begin perform 1; return new; end; $$ language plpgsql;
> > CREATE FUNCTION
> > alvherre=# select foo();
> > foo
> > -----
> >
> > (1 fila)
>
> And?

And the source says that this is not allowed:

/* Disallow pseudotype result, except VOID or RECORD */
/* (note we already replaced polymorphic types) */
if (typeStruct->typtype == TYPTYPE_PSEUDO)
{
if (rettypeid == VOIDOID ||
rettypeid == RECORDOID)
/* okay */ ;
else if (rettypeid == TRIGGEROID)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("trigger functions can only be called as triggers")));
else
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("plpgsql functions cannot return type %s",
format_type_be(rettypeid))));
}

> The function returns a TRIGGER, not a value.

Precisely.

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-10-08 20:27:28 Re: WITH RECURSIVE ... CYCLE in vanilla SQL: issues with arrays of rows
Previous Message Jaime Casanova 2008-10-08 19:30:48 Re: trigger functions broken?