Re: [HACKERS] LIMITing number of results in a VIEW with global variables

2011-10-16 Thread Florian Pflug
On Oct15, 2011, at 14:52 , Thomas Girault wrote: > Alternatively, we could also set the alpha value before the query : > > SELECT set_alpha(0.1); SELECT age, young(age) FROM employees WHERE > young(age); That's certainly much safer. > I would be very interested to know if there is smarter way to

Re: [HACKERS] LIMITing number of results in a VIEW with global variables

2011-10-15 Thread Thomas Girault
Hello Florian, It seems dangerous for a cast to modify global state such a MU. The > evaluation > order of functions during query execute isn't always easy to guess, and may > change depending on the execution plan. I supposed that fuzzy2bool is called just before the terminal evaluation of the

Re: [HACKERS] LIMITing number of results in a VIEW with global variables

2011-10-15 Thread Thomas Girault
Hello, Thank you for your answer Robert. > Well, SQL, our our dialect of it anyway, doesn't have global > variables. So I think the above is going to throw a syntax error. > You may have global variables in your C code, but those won't be > visible from the SQL level. I was wrong in the definit

Re: [HACKERS] LIMITing number of results in a VIEW with global variables

2011-10-15 Thread Florian Pflug
On Oct14, 2011, at 16:43 , Thomas Girault wrote: > CREATE OR REPLACE FUNCTION fuzzy2bool(FLOAT) > RETURNS BOOLEAN LANGUAGE SQL AS 'SELECT set_mu($1);SELECT $1 > get_alpha()'; It seems dangerous for a cast to modify global state such a MU. The evaluation order of functions during query execute is

Re: [HACKERS] LIMITing number of results in a VIEW with global variables

2011-10-15 Thread Robert Haas
On Fri, Oct 14, 2011 at 10:43 AM, Thomas Girault wrote: > I am now trying to limit the number of results in the view according > to the global value K : > > CREATE OR REPLACE VIEW filtered_employees AS >    SELECT *, get_mu() as mu >    FROM employees >    ORDER BY mu DESC >    LIMIT K; Well, SQL