[SQL] Syntax question: use of join/using with fully qualified table name

2008-01-27 Thread Bryce Nesbitt
I've got a join where a certain column name appears twice: select username,last_name from eg_member join eg_membership using (member_id) join eg_account using (account_id) join eg_person using (person_id); ERROR: common column name "person_id" appears more than once in left table My first incli

Re: [SQL] Syntax question: use of join/using with fully qualified table name

2008-01-27 Thread Martin Marques
Bryce Nesbitt escribió: I've got a join where a certain column name appears twice: select username,last_name from eg_member join eg_membership using (member_id) join eg_account using (account_id) join eg_person using (person_id); ERROR: common column name "person_id" appears more than once in l

Re: [SQL] Syntax question: use of join/using with fully qualified table name

2008-01-27 Thread Tom Lane
Bryce Nesbitt <[EMAIL PROTECTED]> writes: > I've got a join where a certain column name appears twice: > select username,last_name from eg_member join eg_membership using > (member_id) join eg_account using (account_id) join eg_person using > (person_id); > ERROR: common column name "person_id" ap

[SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Bryce Nesbitt
Hmm. Seemed so simple. But how do I get the number of years an interval represents? extract is clearly the wrong way: stage=# select 'now()-'1987-02-01' as interval,extract(year from now()-'1987-02-01') as age; interval | age --+- 7665 days 18:05:51.

Re: [SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Adrian Klaver
On Sunday 27 January 2008 6:30 pm, Bryce Nesbitt wrote: > Hmm. Seemed so simple. But how do I get the number of years an > interval represents? extract is clearly the wrong way: > > stage=# select 'now()-'1987-02-01' as interval,extract(year from > now()-'1987-02-01') as age; > interval

Re: [SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Tom Lane
Bryce Nesbitt <[EMAIL PROTECTED]> writes: > Hmm. Seemed so simple. But how do I get the number of years an > interval represents? extract is clearly the wrong way: There is nothing simple about datetime calculations, ever :-( Let me exhibit why this particular case is not as simple as you coul

Re: [SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Bryce Nesbitt
Sigh. Ok, I settled on: select '1987-01-29'::timestamp + interval '21 years' > now(); Which is closer to what I wanted anyway (this was all about determining who was under 21 years old).  This at least should be robust over leap years. Tom Lane wrote: There is nothing simple about datetim

Re: [SQL] extract or date_part on an interval? How many e

2008-01-27 Thread Michael Glaesemann
On Jan 27, 2008, at 23:51 , Bryce Nesbitt wrote: Sigh. Ok, I settled on: select '1987-01-29'::timestamp + interval '21 years' > now(); Which is closer to what I wanted anyway (this was all about determining who was under 21 years old). This at least should be robust over leap years. I th

[SQL] Slow Query problem

2008-01-27 Thread Premsun Choltanwanich
Dear All, I am currently using PostgreSQL database version 8.0.13.  My problem relates to a slow result when a query using a defined view joins to another table for a result. Background:  I have 7 tables of invoice transactions.  The tables are slightly different in that they record different dat