From: Greg Stark <gsstark@mit.edu>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: sramsay@uga.edu
Cc: pgsql-sql@postgresql.org
Subject: Re: functions in WHERE clause
Date: 05 Mar 2006 17:22:38 -0500
Message-ID: <87d5h0pm4x.fsf@stark.xeocode.com> (raw)
In-Reply-To: <4338.1141581591@sss.pgh.pa.us>
References: <20060305151652.GA14216@cantor.english.uga.edu>
<4338.1141581591@sss.pgh.pa.us>
Tom Lane <tgl@sss.pgh.pa.us> writes:
> 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.
I think what's going on here is that he doesn't really want a function in the
programming sense. A function takes arguments and returns a result based on
those arguments. It would be trivial to make a function that returns true or
false for his constraints but it would require passing in the columns as well
as the values he's testing against. So it would be "xpath(ltreecolumn, 42, 47)".
What he's looking for is a convenience macro that hides the columns he's
testing against so he doesn't have to write the columns in every query. So he
can just type "xpath(42,47)" without retyping "ltreecolumn".
Afaik there's no functionality for this in Postgres. functions aren't given
any context information when they're executed aside from the arguments passed.
If I understand what you want then I think you're much better off just typing
the name of the column you're testing against explicitly every time anyways.
One day you'll need more flexibility or you'll have someone else reading the
code and you'll be glad you're not hiding what's going on and hard coding
column names inside some macro function anyways.
--
greg
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: gsstark@mit.edu, tgl@sss.pgh.pa.us, sramsay@uga.edu
Subject: Re: functions in WHERE clause
In-Reply-To: <87d5h0pm4x.fsf@stark.xeocode.com>
* 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