Re: functions in WHERE clause - Mailing list pgsql-sql

From Tom Lane
Subject Re: functions in WHERE clause
Date
Msg-id 4338.1141581591@sss.pgh.pa.us
Whole thread Raw
In response to functions in WHERE clause  (sramsay@uga.edu)
Responses Re: functions in WHERE clause
List pgsql-sql
sramsay@uga.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


pgsql-sql by date:

Previous
From: Karsten Hilbert
Date:
Subject: Re: Check/unique constraint question
Next
From: Tom Lane
Date:
Subject: Re: functions in WHERE clause