pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: sramsay@uga.edu
Cc: pgsql-sql@postgresql.org
Subject: Re: functions in WHERE clause
Date: Sun, 05 Mar 2006 12:59:51 -0500
Message-ID: <4338.1141581591@sss.pgh.pa.us> (raw)
In-Reply-To: <20060305151652.GA14216@cantor.english.uga.edu>
References: <20060305151652.GA14216@cantor.english.uga.edu>

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



view thread (11+ messages)  latest in thread

Message-ID: <4338.1141581591@sss.pgh.pa.us>
Permalink:  ../4338.1141581591@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/4338.1141581591@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, sramsay@uga.edu
  Subject: Re: functions in WHERE clause
  In-Reply-To: <4338.1141581591@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox