[SQL] optimize self-join query

2011-10-27 Thread Ty Busby
I have a table that stores a very large starting number called epc_start_numeric and a quantity. I've apparently built the most inefficient query possible for doing the job I need: find out if any records overlap. Imagine the epc_start_numeric + quantity representing a block of numbers. I ne

[SQL] how to use explain analyze

2011-10-27 Thread alan
I'm new to postgres and was wondering how to use EXPLAIN ANALYZE Can I use the output from ANALYZE EXPLAIN to estimate or predict the actual time it would take for a given query to return? I ask because I'm writing a typical web app that allows the user to build and submit a query to my DB.

[SQL] How to obtain a coalesce aggregation in a GROUP BY query?

2011-10-27 Thread Federico Dal Maso
I need write a query like this select coalesce_agg(col order by col asc) from some_table group by other_col clearly the col column is nullable. which is the best way (in terms of performance too) to obtain this? Are there any built-in aggregate function or should I write a new aggregate function

Re: [SQL] how to use explain analyze

2011-10-27 Thread Brent Dombrowski
On Oct 25, 2011, at 7:12 AM, alan wrote: > I'm new to postgres and was wondering how to use EXPLAIN ANALYZE > > Can I use the output from ANALYZE EXPLAIN to estimate or predict the > actual time > it would take for a given query to return? > > I ask because I'm writing a typical web app tha

Re: [SQL] optimize self-join query

2011-10-27 Thread Tom Lane
Ty Busby writes: > I have a table that stores a very large starting number called > epc_start_numeric and a quantity. I've apparently built the most inefficient > query possible for doing the job I need: find out if any records overlap. > Imagine the epc_start_numeric + quantity representing

[SQL] Different order by behaviour depending on where clause?

2011-10-27 Thread Jan Bakuwel
Hi, I have a compound query with some grouping, having and order by's saved as a view, say with name "myview". A) select * from "myview" returns the results as expected in the correct order (the order by is on fields "Category", "Year", "Month" and a few other fields). The results are correctly o

Re: [SQL] optimize self-join query

2011-10-27 Thread Lee Hachadoorian
On Tue, Oct 25, 2011 at 2:37 PM, Ty Busby wrote: > I have a table that stores a very large starting number called > epc_start_numeric and a quantity. I've apparently built the most > inefficient query possible for doing the job I need: find out if any records > overlap. Imagine the epc_start_nu

Re: [SQL] Different order by behaviour depending on where clause?

2011-10-27 Thread Pavel Stehule
Hello 2011/10/28 Jan Bakuwel : > Hi, > > I have a compound query with some grouping, having and order by's saved > as a view, say with name "myview". > > A) select * from "myview" returns the results as expected in the correct > order (the order by is on fields "Category", "Year", "Month" and a fe