Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread John Lister
Cheers oliverios and tom for your speedy replies. Unfortunately using v8.3 so the new functions are out. A big credit to oliverios for his sql fu, that seems to do exactly what I want and I think I pretty much understand the query. I always forget the comparison on the rows when thinking about g

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread Oliveiros d'Azevedo Cristina
Hi, John. I am not familiar with the functions Tom's indicated and I'm sure they constitute a much more straightfoward to solve your problem. Meanwhile, if you'd like to solve it with just SQL give this a try and see if it gives you the result you want Best, Oliveiros SELECT product_id, MIN(p

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread Andreas Kretschmer
John Lister wrote: > Hi, I was wondering if it is possible to do this with a single query rather > than iterate over all of the rows in an application: > > I have a table which for brevity looks like: > create table offers { > integer id; > integer product_id; > double price; > } > > wh

Re: [SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread Tom Lane
"John Lister" writes: > Is it possible to obtain the difference between just the minimum price and > the next one up per product, If you're using >= 8.4, try a window function. LEAD or LAG ought to do it. regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql

[SQL] obtaining difference between minimum value and next in size

2010-11-17 Thread John Lister
Hi, I was wondering if it is possible to do this with a single query rather than iterate over all of the rows in an application: I have a table which for brevity looks like: create table offers { integer id; integer product_id; double price; } where for each product there is a number of of

Re: [SQL] PostgreSQL array, recursion and more

2010-11-17 Thread Achilleas Mantzios
Στις Wednesday 17 November 2010 15:22:34 ο/η Ferruccio Zamuner έγραψε: > > /* How to get access to its items then? > */ select (mesh_split('A01.378.610.250.300.792.380')::text[])[1]; -- Achilleas Mantzios -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your

[SQL] PostgreSQL array, recursion and more

2010-11-17 Thread Ferruccio Zamuner
MESH Data Tree: example: Hallux;A01.378.610.250.300.792.380 where: A01 is Body Regions A01.378 is Extremities A01.378.610 is Lower Extremity A01.378.610.250 is Foot A01.378.610.250.300 is Forefoot, Human A01.378.610.250.300.792 is Toes CREATE OR REPLACE FUNCTION mesh_split(text) RETURNS text[]