[SQL] generate_series() with TSTZRANGE

2012-09-12 Thread Wolfe Whalen
Hi everyone! I'm new around here, so please forgive me if this is a bit trivial. It seems that generate_series() won't generate time stamp ranges. I googled around and didn't see anything handy, so I wrote this out and thought I'd share and see if perhaps there was a better way to do it: SELECT

Re: [SQL] ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D

2012-09-12 Thread Gavin Flower
On 13/09/12 09:44, Rodrigo Rosenfeld Rosas wrote: This is my first message in this list :) I need to be able to sort a query by column A, then B or C (which one is smaller, both are of the same type and table but on different left joins) and then by D. How can I do that? Thanks in advance, Rod

[SQL] pg_restore problem

2012-09-12 Thread Kjell Øygard
Morning guys... I have two servers , one with postgres 9.2rc1 and one with postgres 9.1.4. I need to do a restore from a dump from 9.1.4 to 9.2rc1 and I get this error: pg_restore: [archiver (db)] Error from TOC entry 177675; 2613 579519 BLOB 579519 primar pg_restore: [archiver (db)] could not ex

Re: [SQL] ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D

2012-09-12 Thread Rodrigo Rosenfeld Rosas
Em 12-09-2012 19:34, Gavin Flower escreveu: On 13/09/12 09:44, Rodrigo Rosenfeld Rosas wrote: This is my first message in this list :) I need to be able to sort a query by column A, then B or C (which one is smaller, both are of the same type and table but on different left joins) and then by D

Re: [SQL] ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D

2012-09-12 Thread Rodrigo Rosenfeld Rosas
Replied just to Samuel and forgot to include the list in my reply. Doing that now, sorry... Em 12-09-2012 18:53, Samuel Gendler escreveu: you put a conditional clause in the order by statement, either by referencing a column that is populated conditionally, like this select A, when B < C Then

Re: [SQL] ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D

2012-09-12 Thread Samuel Gendler
you put a conditional clause in the order by statement, either by referencing a column that is populated conditionally, like this select A, when B < C Then B else C end as condColumn, B, C, D from ... where ... order by 1,2, 5 or select A, when B < C Then B else C end as condColumn, B, C, D from

[SQL] ORDER BY COLUMN_A, (COLUMN_B or COLUMN_C), COLUMN_D

2012-09-12 Thread Rodrigo Rosenfeld Rosas
This is my first message in this list :) I need to be able to sort a query by column A, then B or C (which one is smaller, both are of the same type and table but on different left joins) and then by D. How can I do that? Thanks in advance, Rodrigo. -- Sent via pgsql-sql mailing list (pgsql-s

Re: [SQL] weird join producing too many rows

2012-09-12 Thread Gary Stainburn
Hi, Thanks for this. I did eventually discover the cause being other rows in the pieces_requests table that I hadn't thought about. The short answer to your second part is that I don't know why I did it that way. Presumably when I first wrote it there was a reason. Gary On Wednesday 12 Septe

Re: [SQL] weird join producing too many rows

2012-09-12 Thread Samuel Gendler
I'll admit I don't see any reason why you should get duplicate rows based on the data you've provided, but I am wondering why you are using the subquery instead of just 'where r.r_id = 5695' select p.p_id, r.pr_ind from pieces p join pieces_requests r on p.p_id = r.p_id where r.r_id = 5695 Though

[SQL] weird join producing too many rows

2012-09-12 Thread Gary Stainburn
I have a pieces table with p_id as primary key. I have a requests table with r_id as primary key. I have a pieces_requests table with (p_id, r_id) as primary key, and an indicator pr_ind reflecting the state of that relationship A single select of details from the pieces table based on an entry i