[SQL] getting duplicate number is there a

2005-05-16 Thread Joel Fradkin
I was using SET TRANSACTION ISOLATION LEVEL SERIALIZABLE in MSSQL.   Is there something similar in postgres to ensure its not in the middle of being updated?       sql = "SELECT COUNT(*) FROM tblcase WHERE LocationID = " & intLocationID & _   " and substr(casenu

Re: [SQL] sub-selects

2005-05-16 Thread PFC
SELECT foo.*, npoints( foo.g ) FROM (SELECT a, (select b from c where d = e limit 1) AS g FROM f WHERE isValid( g )) AS foo ? ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail comma

[SQL] sub-selects

2005-05-16 Thread Mark Fenbers
Is there a way to make a query more efficient by executing a sub-select only once? In a query such as: SELECT a, (select b from c where d = e limit 1), npoints( (select b from c where d = e limit 1) )     FROM f     WHERE isValid( (select b from c where d = e limit 1) ); I do the same sub-se

Re: [SQL] ORDER BY handling mixed integer and varchar values

2005-05-16 Thread Ragnar Hafstað
On Mon, 2005-05-16 at 11:47 -0700, David B wrote: (sorting text columns numerically) > And of course I get stuff ordered as I want it. > BUT… with many product categories being numeric based they come out in > wrong order '10 comes before 2" etc. > > So I tried > Select product_desc, product_

Re: [SQL] ORDER BY handling mixed integer and varchar values

2005-05-16 Thread Rod Taylor
> Is there any elegent query you folks can think of that combines the > two so I can one query that has alpha sorting on alpha categories and > numeric sorting on numeric values that are in the same column?? select * from r order by (case when col ~ '^[0-9]+$' THEN lpad(col, 10, '0') else col end)

Re: [SQL] ORDER BY handling mixed integer and varchar values

2005-05-16 Thread Edmund Bacon
Well the following seems to work, althoug I do not believe it is guarenteed to: (select * from table where column ~'\\d+' order by cast(colum as integer)) union all (select * from table where column !~ '\\d+' order by column); This could be quite slow if table is large Alternatively: select * fro

Re: [SQL] ORDER BY handling mixed integer and varchar values

2005-05-16 Thread PFC
Is there any elegent query you folks can think of that combines the two so I can one query that has alpha sorting on alpha categories and numeric sorting on numeric values that are in the same column?? solution 1 (fast) make a separate column which contains the integer value (updated via a trigge

[SQL] ORDER BY handling mixed integer and varchar values

2005-05-16 Thread David B
Hi All, I have a tabe Product_desc varchar(100) Product_price integer Product_catvarchar(100) The problem… We have categories such as: Electronics White Goods 1 2 5 15 25 etc I have a query Select product_desc, product_price, product_cat Order by product_cat, product_price And of cours

Re: [SQL] choosing index to use

2005-05-16 Thread PFC
Try indexing on client, time instead of time, client... putting the equality condition on the first column of the index can make it faster. Else, analyze, increase your stats, etc... On Mon, 16 May 2005 13:39:40 +0200, Ilya A. Kovalenko <[EMAIL PROTECTED]> wrote: Greetings, How can I co

[SQL] choosing index to use

2005-05-16 Thread Ilya A. Kovalenko
Greetings, How can I control which indexes will or won't be used by query ? I never think, that I'll need something like this. Short version: Simple SELECT query perfomance speeds up (10x-20x) after _removing_ one of indexes. Because (as EXPLAIN shows), after removing, query switches