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 set

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 toma.gira...@gmail.com 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    

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

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 definition

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

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

2011-10-14 Thread Thomas Girault
Hello, I am writing an extension to easily execute queries with conditions expressing constraints in fuzzy logics. I wrote some C functions that get or set global variables in C. The variables are MU (FLOAT : degree of a fuzzy predicate), ALPHA (FLOAT : threshold for filtering predicates) and K