Re: join functions

From: Marko Tiikkaja <marko(dot)tiikkaja(at)cs(dot)helsinki(dot)fi>
To: Zotov <zotov(at)oe-it(dot)ru>
Cc: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: join functions
Date: 2011-01-08 12:50:39
Message-ID: B77162C8-2ADD-42BB-8DAD-CB6D04F6272B@cs.helsinki.fi
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 5 Jan 2011, at 02:12, Zotov <zotov(at)oe-it(dot)ru> wrote:
> Why doesn`t work this query?
> select table1.field1, func1.field2 from table1 left outer join func1
> (table1.field1) on true where func1.field3 in (20, 100);

The approach people usually use is:

SELECT
f1, (fn).field2
FROM
(
SELECT
field1 as f1, func1(field1) as fn
FROM
table1
OFFSET 0
) ss
WHERE
(fn).field3 IN (20, 100)
;

OFFSET 0 is there to prevent the function from getting called more
than once. Also note that this will scan the whole table. There
might be a way to avoid that by creating an index on ((func1
(field1)).field3) and removing OFFSET 0, but only if the function is
IMMUTABLE.

Regards,
Marko Tiikkaja

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joel Jacobson 2011-01-08 13:05:17 Re: obj_unique_identifier(oid)
Previous Message Dimitri Fontaine 2011-01-08 12:17:51 Re: We need to log aborted autovacuums