Re: [SQL] 8.4.1 distinct query WITHOUT order by

2009-12-22 Thread Scott Marlowe
On Tue, Dec 22, 2009 at 12:11 AM, msi77 ms...@yandex.ru wrote: What are the ramifications of renaming the table (containing 8000 rows) and creating a view of the same name? View does not admit ORDER BY clause, at least, Standard does not. Postgres certainly allows it, but I don't think it

[SQL] short-cutting if sum()constant

2009-12-22 Thread Ivan Sergio Borgonovo
Hi, I'd like to know if select sum(qty) from t where status=37; is constant. qty is always 0. Is there a way to skip examining further rows and return a result ASAP? -- Ivan Sergio Borgonovo http://www.webthatworks.it -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Filip Rembiałkowski
2009/12/22 Ivan Sergio Borgonovo m...@webthatworks.it Hi, Hi :-) I'd like to know if select sum(qty) from t where status=37; is constant. qty is always 0. Is there a way to skip examining further rows and return a result ASAP? With plain SQL, no. With a user defined function

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Adam Tauno Williams
On Tue, 2009-12-22 at 13:35 +0100, Ivan Sergio Borgonovo wrote: Hi, I'd like to know if select sum(qty) from t where status=37; is constant. qty is always 0. Is there a way to skip examining further rows and return a result ASAP? SELECT SUM(object_version) FROM date_x WHERE owner_id =

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread A. Kretschmer
In response to Ivan Sergio Borgonovo : Hi, I'd like to know if select sum(qty) from t where status=37; is constant. qty is always 0. Is there a way to skip examining further rows and return a result ASAP? I think no. But you can create a new table with 2 columns: status

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread msi77
Does PG support CTE? You can try it. In response to Ivan Sergio Borgonovo : Развернуть Hi, I'd like to know if select sum(qty) from t where status=37; is constant. qty is always 0. Is there a way to skip examining further rows and return a result ASAP? I think

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Ivan Sergio Borgonovo
On Tue, 22 Dec 2009 14:48:55 +0100 Filip Rembiałkowski plk.zu...@gmail.com wrote: With plain SQL, no. With a user defined function in PL/PgSQL, yes. thanks to all. I'm on 8.3 so no CTE. I was hoping there was some way to write it in plain SQL. I'm planning to wrap everything in a plpgsql

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Andreas Kretschmer
msi77 ms...@yandex.ru wrote: Does PG support CTE? Since 8.4 yes. You can try it. Sorry, but i don't know how a CTE can help in this case, can you explain that? Andreas -- Really, I'm not out to destroy Microsoft. That will just be a completely unintentional side effect.

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread msi77
Sorry, but i don't know how a CTE can help in this case, can you explain I mean RECURSIVE CTE. You can check your condition on each iteration and stop execution when condition is false. Sergey msi77 ms...@yandex.ru wrote: Развернуть Does PG support CTE? Since 8.4 yes. Развернуть

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Pavel Stehule
Hello I found one ugly trick. You can multiply lines and SUM cons could be replaced limit clause: postgres=# select * from data; a --- 3 2 1 4 2 3 (6 rows) Then SELECT * FROM WHERE and stop when SUM(a) = n then postgres=# select generate_series(1,a) from data; generate_series

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Ivan Sergio Borgonovo
On Wed, 23 Dec 2009 00:00:31 +0100 Ivan Sergio Borgonovo m...@webthatworks.it wrote: On Tue, 22 Dec 2009 20:47:18 +0100 Pavel Stehule pavel.steh...@gmail.com wrote: Hello I found one ugly trick. You can multiply lines and SUM cons could be replaced limit clause: The trick is

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Ivan Sergio Borgonovo
On Wed, 23 Dec 2009 01:09:40 +0100 Ivan Sergio Borgonovo m...@webthatworks.it wrote: On Wed, 23 Dec 2009 00:00:31 +0100 Ivan Sergio Borgonovo m...@webthatworks.it wrote: On Tue, 22 Dec 2009 20:47:18 +0100 Pavel Stehule pavel.steh...@gmail.com wrote: Hello I found one ugly

Re: [SQL] short-cutting if sum()constant

2009-12-22 Thread Pavel Stehule
2009/12/23 Ivan Sergio Borgonovo m...@webthatworks.it: On Wed, 23 Dec 2009 01:09:40 +0100 Ivan Sergio Borgonovo m...@webthatworks.it wrote: On Wed, 23 Dec 2009 00:00:31 +0100 Ivan Sergio Borgonovo m...@webthatworks.it wrote: On Tue, 22 Dec 2009 20:47:18 +0100 Pavel Stehule