Re: Strange order of execution with rule

From: han(dot)holl(at)informationslogik(dot)nl
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Strange order of execution with rule
Date: 2005-10-21 11:22:40
Message-ID: 200510211322.40950.han.holl@informationslogik.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday 20 October 2005 23:48, Tom Lane wrote:

> Give us a test case to demonstrate this assertion. It works as expected
> AFAICT.
>
Ok, it has to do with C functions:
#include <postgres.h>
#include <fmgr.h>
#include <sys/time.h>

PG_FUNCTION_INFO_V1(plg_cfie);
Datum
plg_cfie(PG_FUNCTION_ARGS)
{
struct timeval before;
gettimeofday(&before, 0);
elog(NOTICE, "Called cfie %ld.%ld\n",before.tv_sec, before.tv_usec);
PG_RETURN_NULL();
}
/* end-of-plg_cfie */
gcc -fpic -O2 -Wall -c -I /usr/include/pgsql/server/ plg_cfie.c
gcc -shared -o /tmp/plg_cfie.so plg_cfie.o

File test:
CREATE or replace FUNCTION func_display(udps, udps) RETURNS void AS '
a = Time.now
warn sprintf("Called func_display %d.%d", a.tv_sec, a.tv_usec)
' LANGUAGE 'plruby';

create or replace function plg_cfie() returns void as '/tmp/plg_cfie.so'
language c immutable;

CREATE or replace rule update_rule as on update
to udps
do instead (
select func_display(new, old);
select plg_cfie();
);

update udps set ziekenhuis = 'olvg' where rapport = 'T105-00002';
-- end of file test
su postgres -c 'psql palga' <test

CREATE FUNCTION
CREATE FUNCTION
CREATE RULE
NOTICE: Called cfie 1129893542.714536

NOTICE: Called func_display 1129893542.732444
plg_cfie
----------

(1 row)

It's not a plruby issue, I tested with plpgsql (your noti) as well.

Cheers,

Han Holl

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2005-10-21 12:04:45 Re: doc typo sql-reindex.html psql vs. postgres
Previous Message Mark Rae 2005-10-21 11:17:32 Re: transaction limits?