SET within a function? - Mailing list pgsql-general

From Edmund Dengler
Subject SET within a function?
Date
Msg-id Pine.BSO.4.58.0310132109510.12650@cyclops4.esentire.com
Whole thread Raw
Responses Re: SET within a function?  (Bruno Wolff III <bruno@wolff.to>)
List pgsql-general
Hi all!

I am doing some trigger functions that need to find a tuple in another
table. The problem is that this second table is doing some summarization
work, and I need nulls to equal each other.

Basically, in the trigger I do a:

  SELECT INTO ... x
  FROM table1
  WHERE ...(some straightforward x = old.x)...
    AND (x1 = old.x1 OR (x1 is null and old.x1 is null))
    AND (x2 = old.x2 OR (x2 is null and old.x2 is null))
    AND (x3 = old.x3 OR (x3 is null and old.x3 is null));

The problem is that an index is used to perform the straightforward stuff,
and then the x1,x2,x3 is done via an index scan, rather than directly.
Unfortunately for the data set I have, it can be clustered pretty badly
around the straightforward stuff, and so the scan can take multiple
seconds per call.

I think if I could do a 'SET TRANSFORM_NULL_EQUALS TO ON' then this might
fix the issue (don't know, haven't tried it yet). My question is: can this
be done within a function such that at the end of the function, the value
is reset back to value upon entering (kind of like 'SET LOCAL' except for
just the length of the function call). Is this possible?

Thanks!
Ed

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Humor me: Postgresql vs. MySql (esp. licensing)
Next
From: "D. Stimits"
Date:
Subject: Re: [INTERFACES] more on undefined reference to 'pg_detoast_datum'