Re: functions in WHERE clause

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: sramsay(at)uga(dot)edu, pgsql-sql(at)postgresql(dot)org
Subject: Re: functions in WHERE clause
Date: 2006-03-05 22:22:38
Message-ID: 87d5h0pm4x.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Michael Louie Loria 2006-03-06 01:23:29 Visual and PostgreSQL
Previous Message Tom Lane 2006-03-05 21:59:38 Re: Help with distinctly non-intuitive rule behaviour