Re: [SQL] functions in WHERE clause

2006-03-27 Thread Markus Schaber
Hi, Steve, [EMAIL PROTECTED] wrote: > SELECT * from some_table WHERE > test_for_equality_is_syntactically_ugly; > The WHERE clause expects the function to return a boolean value. I > can certainly return a boolean value from a function, but here it > seems to me that what the function really ha

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Greg Stark
Tom Lane <[EMAIL PROTECTED]> 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 s

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Stephan Szabo
On Sun, 5 Mar 2006 [EMAIL PROTECTED] wrote: > On Sun, Mar 05, 2006 at 11:38:46AM -0800, Stephan Szabo wrote: > > > But imagine instead that this function is more generic. You know > > > that you're trying to get something that's equal to x and equal to > > > y, but you don't know (until the func

Re: [SQL] functions in WHERE clause

2006-03-05 Thread sramsay
On Sun, Mar 05, 2006 at 11:38:46AM -0800, Stephan Szabo wrote: > > But imagine instead that this function is more generic. You know > > that you're trying to get something that's equal to x and equal to > > y, but you don't know (until the function is called) what those > > rvalues should be. In

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Stephan Szabo
On Sun, 5 Mar 2006 [EMAIL PROTECTED] wrote: > On Sun, Mar 05, 2006 at 01:16:40PM -0500, Tom Lane wrote: > > [EMAIL PROTECTED] writes: > > That would work fine if you said RETURNS SETOF ltree. > > > > That should work too, except that you are trying to return a record > > not an ltree value. Try "

Re: [SQL] functions in WHERE clause

2006-03-05 Thread sramsay
On Sun, Mar 05, 2006 at 01:16:40PM -0500, Tom Lane wrote: > [EMAIL PROTECTED] writes: > That would work fine if you said RETURNS SETOF ltree. > > That should work too, except that you are trying to return a record > not an ltree value. Try "RETURN NEXT tree.ltree". > > > Because SETOF won't work

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Tom Lane
[EMAIL PROTECTED] writes: > You can't do this: > CREATE FUNCTION xpath(lquery) RETURNS ltree AS $$ > SELECT ltree FROM event WHERE ltree ~ $1; > $$ LANGUAGE SQL; That would work fine if you said RETURNS SETOF ltree. > But I also can't get this kind of thing to work: > CREATE FUNCTION xpath(lq

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Tom Lane
[EMAIL PROTECTED] 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 mytes

Re: [SQL] functions in WHERE clause

2006-03-05 Thread sramsay
On Sun, Mar 05, 2006 at 10:26:35AM -0700, Michael Fuhr wrote: > On Sun, Mar 05, 2006 at 10:16:52AM -0500, [EMAIL PROTECTED] wrote: > > 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 cl

Re: [SQL] functions in WHERE clause

2006-03-05 Thread Michael Fuhr
On Sun, Mar 05, 2006 at 10:16:52AM -0500, [EMAIL PROTECTED] wrote: > 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, > but I'm having no end of trouble. Would a view work?