Re: [SQL] stored procedures for complex SELECTs

2006-01-18 Thread Michael Glaesemann
On Jan 19, 2006, at 8:17 , [EMAIL PROTECTED] wrote: Are there performance advantages that can be achieved by wrapping a complex SELECT into a stored procedure? I believe it depends on the procedural language. If it's SQL, I think it may be inlined, so you'd have overhead due to the stored p

[SQL] stored procedures for complex SELECTs

2006-01-18 Thread alex-lists-pgsql
Are there performance advantages that can be achieved by wrapping a complex SELECT into a stored procedure? Alex ---(end of broadcast)--- TIP 4: Have you searched our list archives? http://archives.postgresql.org

Re: [SQL] Matching several rows

2006-01-18 Thread Vraj Mohan
It is easier to think of this as SET INTERSECTION which leads to: SELECT id FROM urights WHERE right = 2 INTERSECT SELECT id FROM urights WHERE right = 5 INTERSECT SELECT id FROM urights WHERE right = 10 Ivan Steganov wrote: Thank you to everyone for the great help! I will evaluate all methods

Re: [SQL] [GENERAL] bug with if ... then ... clause in views

2006-01-18 Thread Jeff
Emil Rachovsky wrote: While trying to create some views I stumbled on some problem with using the if-then clause. Here is a simple example : CREATE OR REPLACE VIEW public.SomeView as select d.id, if (true) then d.DocNumber endif from public.Z_Documents as d; I get the following error : syn

Re: [SQL] Matching several rows

2006-01-18 Thread Patrick JACQUOT
Michael Glaesemann wrote: On Jan 18, 2006, at 21:48 , Volkan YAZICI wrote: AFAICS, the bottleneck in above query is ANY(ARRAY[]) clause usage. Instead of that, if you replace «rights = ANY(ARRAY[2,5,10])» with «rights IN (2,5,10)» it's overhead decreases to 0.200-0.300ms domain. explain an

Re: [SQL] Matching several rows

2006-01-18 Thread Ivan Steganov
Thank you to everyone for the great help!I will evaluate all methods in our query (It is actually well complexer then this sample) and choose the best one.Is there any "scientific" name to this kind of "several rows match for one result" data selection? Ivan

Re: [SQL] Matching several rows

2006-01-18 Thread Michael Glaesemann
On Jan 18, 2006, at 21:48 , Volkan YAZICI wrote: AFAICS, the bottleneck in above query is ANY(ARRAY[]) clause usage. Instead of that, if you replace «rights = ANY(ARRAY[2,5,10])» with «rights IN (2,5,10)» it's overhead decreases to 0.200-0.300ms domain. explain analyze SELECT id FROM ( SE

Re: [SQL] Matching several rows

2006-01-18 Thread Volkan YAZICI
On Jan 18 09:33, Michael Glaesemann wrote: > On Jan 18, 2006, at 20:55 , Volkan YAZICI wrote: > >SELECT t.id > >FROM (SELECT id, sum(1) AS s > > FROM id_n_rights > > WHERE rights = ANY(ARRAY[2,5,10]) > > GROUP BY id) AS t > >WHERE t.s = 3; AFAICS, the bottleneck in above query is

Re: [SQL] bug with if ... then ... clause in views

2006-01-18 Thread Daryl Richter
On Jan 18, 2006, at 4:18 AM, Emil Rachovsky wrote: While trying to create some views I stumbled on some problem with using the if-then clause. Here is a simple example : CREATE OR REPLACE VIEW public.SomeView as select d.id, if (true) then d.DocNumber endif from public.Z_Documents as d; I

Re: [SQL] Matching several rows

2006-01-18 Thread Michael Glaesemann
On Jan 18, 2006, at 20:55 , Volkan YAZICI wrote: On Jan 18 05:43, Ivan Steganov wrote: IDRIGHT - 201 202 205 2010 302 3010 Now I need to find out which IDs have, say rights 2 AND 5 AND 10. SELECT t.id FROM (SELECT i

Re: [SQL] Matching several rows

2006-01-18 Thread Volkan YAZICI
Hi, On Jan 18 05:43, Ivan Steganov wrote: > IDRIGHT > - > 201 > 202 > 205 > 2010 > 302 > 3010 > > Now I need to find out which IDs have, say rights 2 AND 5 AND 10. SELECT t.id FROM (SELECT id, sum(1) AS s FROM

Re: [SQL] Still struggling with history tables

2006-01-18 Thread Michael Glaesemann
On Jan 18, 2006, at 19:23 , Achilleus Mantzios wrote: Generally it is very hard to distinguish between two kind of UPDATES: a) UPDATEs that mean real data updates and they should be recorded to the history system. b) UPDATEs that are just false data entry, and they should mean just plain corre

Re: [SQL] bug with if ... then ... clause in views

2006-01-18 Thread Michael Glaesemann
On Jan 18, 2006, at 18:18 , Emil Rachovsky wrote: CREATE OR REPLACE VIEW public.SomeView as select d.id, if (true) then d.DocNumber endif from public.Z_Documents as d; I get the following error : syntax error at or near "then" at character 72 Well, one problem is that IF ... ENDIF is the

Re: [SQL] Still struggling with history tables

2006-01-18 Thread Achilleus Mantzios
O Ken Winter έγραψε στις Jan 17, 2006 : > Friends ~ > > I'm still trying to implement a solution to the requirement to keep a > complete history of data changes to a "person" table. (See earlier > correspondence below.) I'm trying for a variant of the architecture > suggested by Richard Huxton

[SQL] bug with if ... then ... clause in views

2006-01-18 Thread Emil Rachovsky
While trying to create some views I stumbled on some problem with using the if-then clause. Here is a simple example : CREATE OR REPLACE VIEW public.SomeView as select d.id, if (true) then d.DocNumber endif from public.Z_Documents as d; I get the following error : syntax error at or near "t