rendered paste bodydltphotography.co.uk=# explain SELECT *, to_number('0' || picfilename,'999999999') as numeric FROM tblPictures WHERE galleryid='KingwaterDressageWaltonBrampton8thOctober2006' ORDER BY substr(picfilename,0,2), numeric ASC;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Sort (cost=533.11..535.78 rows=1069 width=107)
Sort Key: substr((picfilename)::text, 0, 2), to_number(('0'::text || (picfilename)::text), '999999999'::text)
-> Index Scan using picfilename_num_idx on tblpictures (cost=0.00..479.33 rows=1069 width=107)
Index Cond: ((galleryid)::text = 'KingwaterDressageWaltonBrampton8thOctober2006'::text)
(4 rows)