Re: functions in WHERE clause

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: functions in WHERE clause
Дата
Msg-id 87d5h0pm4x.fsf@stark.xeocode.com
обсуждение исходный текст
Ответ на Re: functions in WHERE clause  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-sql
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



В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Help with distinctly non-intuitive rule behaviour
Следующее
От: Michael Louie Loria
Дата:
Сообщение: Visual and PostgreSQL