Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Guillaume Lelarge
Le jeudi 19 novembre 2009 à 01:20:24, Kris Kewley a écrit : > Could you not create a function to do this instead? > > Set var_limit = 20% of row count > Replace subquery with var_limit > Sure, see the previous mails from Pavel. You can also put the percent as a parameter of the function. --

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Kris Kewley
Could you not create a function to do this instead? Set var_limit = 20% of row count Replace subquery with var_limit Kris On 18-Nov-09, at 14:27, Guillaume Lelarge wrote: Le mercredi 18 novembre 2009 à 20:24:09, Another Trad a écrit : No, It doesn't. In my machine: First select ERROR:

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Pavel Stehule
2009/11/18 Lee Hachadoorian : > On Wed, Nov 18, 2009 at 2:30 PM, Pavel Stehule > wrote: >> yes, and don't use 20%. >> >> select * from foo order by somecol limit (select (count(*)*0.2)::int from >> foo) >> >> Regards >> Pavel > > Is this faster on a large table? Because (select (count(*)*20/100)

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Pavel Stehule
2009/11/18 Another Trad : > But there is any way to do it? CREATE OR REPLACE twenty() RETURNS SETOF foo AS $$ DECLARE rows int; r record; BEGIN rows := (SELECT count(*) FROM foo); FOR r IN EXECUTE 'SELECT * FROM r ORDER BY some col LIMIT ' || (rows * 0.2)::int LOOP RETURN NEXT r; END

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Lee Hachadoorian
On Wed, Nov 18, 2009 at 2:30 PM, Pavel Stehule wrote: > yes, and don't use 20%. > > select * from foo order by somecol limit (select (count(*)*0.2)::int from foo) > > Regards > Pavel Is this faster on a large table? Because (select (count(*)*20/100)) worked fine. -- Sent via pgsql-sql mailing l

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Pavel Stehule
2009/11/18 Guillaume Lelarge : > Le mercredi 18 novembre 2009 à 20:24:09, Another Trad a écrit : >> No, It doesn't. >> In my machine: >> >> First select >> ERROR:  syntax error at end of input >> LINE 1: select * from rapadura.cliente limit 20% >>                                                 ^ >

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Another Trad
But there is any way to do it? 2009/11/18 Guillaume Lelarge > Le mercredi 18 novembre 2009 à 20:24:09, Another Trad a écrit : > > No, It doesn't. > > In my machine: > > > > First select > > ERROR: syntax error at end of input > > LINE 1: select * from rapadura.cliente limit 20% > >

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Guillaume Lelarge
Le mercredi 18 novembre 2009 à 20:24:09, Another Trad a écrit : > No, It doesn't. > In my machine: > > First select > ERROR: syntax error at end of input > LINE 1: select * from rapadura.cliente limit 20% > ^ > Second one: > ERROR: argument of LIMI

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Another Trad
No, It doesn't. In my machine: First select ERROR: syntax error at end of input LINE 1: select * from rapadura.cliente limit 20% ^ Second one: ERROR: argument of LIMIT must not contain subqueries Postgres 8.3 2009/11/18 Lee Hachadoorian > Your

Re: [SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Lee Hachadoorian
Your SQL works for me exactly as it is (substituting a table in my database). What error are you getting? On Wed, Nov 18, 2009 at 2:12 PM, Another Trad wrote: > My question is quite simple: I want to select all the records from my table, > but I want apply a LIMIT of 20% in the lines. like: > sel

[SQL] LIMIT BASED ON PERCENT

2009-11-18 Thread Another Trad
My question is quite simple: I want to select all the records from my table, but I want apply a LIMIT of 20% in the lines. like: select * from client limit 20% I have tried (of course, with no success) this: select * from client limit ((select count(*) from client)*20/100)