Re: functions in WHERE clause

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sramsay(at)uga(dot)edu
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: functions in WHERE clause
Date: 2006-03-05 17:59:51
Message-ID: 4338.1141581591@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

sramsay(at)uga(dot)edu writes:
> I've got one of these:
> SELECT * from some_table WHERE
> test_for_equality_is_syntactically_ugly;
> What I'd like to do is encapsulate the WHERE clause in a function,

You mean like replacing

SELECT * from some_table WHERE x = 42 AND y = 77

with

create function mytest(int,int) returns bool as
$$select $1 = 42 AND $2 = 77$$ language sql;

SELECT * from some_table WHERE mytest(x,y);

A SQL-language function like this should get inlined into the query,
so that you don't lose any performance compared to writing out the
full expression each time.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2006-03-05 18:16:40 Re: functions in WHERE clause
Previous Message sramsay 2006-03-05 17:48:27 Re: functions in WHERE clause