pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedhow to do 'deep queries'?
8+ messages / 4 participants
[nested] [flat]
* how to do 'deep queries'?
@ 2005-09-27 00:34 jeff sacksteder <jsacksteder@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: jeff sacksteder @ 2005-09-27 00:34 UTC (permalink / raw)
To: pgsql-sql
Is there supported syntax to do 'deep' queries? That is where A relates to B
relates to C, returning fields from each table?
This doesn't seem to work. Is there a google-able term for this sort of
query?
select
foo.aaa,
bar.bbb,
baz.ccc
from
foo,bar,baz
where
foo.bar_id = bar.id <http://bar.id;
and
bar.baz_id = baz.id <http://baz.id;
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: how to do 'deep queries'?
@ 2005-09-27 00:45 Stewart Ben (RBAU/EQS4) * <Ben.Stewart@au.bosch.com>
0 siblings, 0 replies; 8+ messages in thread
From: Stewart Ben (RBAU/EQS4) * @ 2005-09-27 00:45 UTC (permalink / raw)
To: pgsql-sql
> Is there supported syntax to do 'deep' queries? That is where
> A relates to B relates to C, returning fields from each table?
>
> This doesn't seem to work. Is there a google-able term for
> this sort of query?
>
> select
> foo.aaa,
> bar.bbb,
> baz.ccc
>
> from
> foo,bar,baz
>
> where
> foo.bar_id = bar.id
> and
> bar.baz_id = baz.id
This works for me..
SELECT table1.state, table2.coursename, table3.firstname
FROM backend.enrolments table1, backend.courses table2, backend.users
table3
WHERE table1.user = table3.employeeno
AND table1.course = table2.courseid;
What errors are you getting?
Best regards,
Ben Stewart
--
Robert Bosch (Australia) Pty. Ltd.
Engineering Quality Services, Student Software Engineer (RBAU/EQS4)
Locked Bag 66 - Clayton South, VIC 3169 - AUSTRALIA
Tel: +61 3 9541-7002 Fax: +61 3 9541-7700
mailto:ben.stewart@au.bosch.com
http://www.bosch.com.au/
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: how to do 'deep queries'?
@ 2005-09-27 00:58 Anthony Molinaro <amolinaro@wgen.net>
0 siblings, 2 replies; 8+ messages in thread
From: Anthony Molinaro @ 2005-09-27 00:58 UTC (permalink / raw)
To: jeff sacksteder <jsacksteder@gmail.com>; pgsql-sql
that query is 100% correct.
it's just an equijoin (a type of inner join) between 3 tables.
the syntax you show is how queries should be written and is more
representative of what a joins between relations really are:
Cartesian products with filters applied
the ansi syntax, the explicit JOIN ... ON stuff is (imho) unnecessary,
useful only for outer joins since all the vendors did it differently.
what you have will work for postgreSQL, I used the syntax you show in my
book
for every single join recipe except for outjoins.
are you seeing errors?
regards,
Anthony
-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of jeff sacksteder
Sent: Monday, September 26, 2005 8:34 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] how to do 'deep queries'?
Is there supported syntax to do 'deep' queries? That is where A relates
to B relates to C, returning fields from each table?
This doesn't seem to work. Is there a google-able term for this sort of
query?
select
foo.aaa,
bar.bbb,
baz.ccc
from
foo,bar,baz
where
foo.bar_id = bar.id
and
bar.baz_id = baz.id
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: how to do 'deep queries'?
@ 2005-09-27 03:35 jeff sacksteder <jsacksteder@gmail.com>
parent: Anthony Molinaro <amolinaro@wgen.net>
1 sibling, 0 replies; 8+ messages in thread
From: jeff sacksteder @ 2005-09-27 03:35 UTC (permalink / raw)
To: Anthony Molinaro <amolinaro@wgen.net>; +Cc: pgsql-sql
Nevermind. It's late here and I'm not thinking clearly. Problem solved.
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: how to do 'deep queries'?
@ 2005-09-27 13:24 Daryl Richter <daryl@brandywine.com>
parent: Anthony Molinaro <amolinaro@wgen.net>
1 sibling, 0 replies; 8+ messages in thread
From: Daryl Richter @ 2005-09-27 13:24 UTC (permalink / raw)
To: pgsql-sql
Anthony Molinaro wrote:
> that query is 100% correct.
>
> it's just an equijoin (a type of inner join) between 3 tables.
>
> the syntax you show is how queries should be written and is more
> representative of what a joins between relations really are:
> Cartesian products with filters applied
>
> the ansi syntax, the explicit JOIN ... ON stuff is (imho) unnecessary,
> useful only for outer joins since all the vendors did it differently.
>
Whether you feel that is unnecessary or not, it *is* the ANSI Standard
and is thus, by definition, "how queries should be written."
In addition to cleaning up the outer join issue, it was added to make
the *intention* of the query clearer.
Because others are likely to read your query many more times than you
write it, clarity of intent *is* important.
> what you have will work for postgreSQL, I used the syntax you show in my
> book
> for every single join recipe except for outjoins.
>
> are you seeing errors?
>
> regards,
> Anthony
[original snipped]
--
Daryl
"We want great men who, when fortune frowns, will not be discouraged."
-- Colonel Henry Knox, 1776
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: how to do 'deep queries'?
@ 2005-09-27 14:23 Anthony Molinaro <amolinaro@wgen.net>
0 siblings, 1 reply; 8+ messages in thread
From: Anthony Molinaro @ 2005-09-27 14:23 UTC (permalink / raw)
To: daryl@brandywine.com; pgsql-sql
Daryl,
> Whether you feel that is unnecessary or not, it *is* the ANSI Standard
> and is thus, by definition, "how queries should be written."
I disagree 100%. Oracle and db2 introduced window functions years
before
Ansi added them. Should we not have used them? It absurd to avoid using
a feature cuz it's not ansi.
Honestly, Don't be a slave to ansi, you miss out on all the great
vendor specific functionality *that you're already paying for*
> it was added to make the *intention* of the query clearer.
More clearer to whom?
Certainly not developers who have been working for many years
using the old syntax.
The intention of the old syntax is perfect. Realize that the problem is
not the old syntax, the problem is the watered down database field
today.
I see this more and more with each interview I conduct looking
for dba's and developers.
You know, it used to be that database developers
had a solid background in math and relational theory.
Sadly, that's not the case anymore...
select * from a,b where a.id=b.id
Suggests a Cartesian product between two relations then a filter to keep
only matching rows.
That's a join. And that syntax is a *perfect* representation of it.
So to whom is ansi more clear? To the person who knows nothing about
databases and decided one day to get a certification and call themselves
an expert?
Or maybe the person who decided one day on a whim to get into databases
and not realize that tons of code from the prior decade use the old
style syntax?
> Because others are likely to read your query many more times than you
> write it, clarity of intent *is* important.
I've never worked in a place that used ANSI only syntax and I've never
had a problem with clarity nor any developers I've worked with.
So, I don't at all get what you're saying...
Old style is short and sweet and perfect.
Ansi dumbed it down, that's the bottom line.
And for people who've been developing for sometime,
It's wholly unnecessary.
Regards,
Anthony
-----Original Message-----
From: pgsql-sql-owner@postgresql.org
[mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Daryl Richter
Sent: Tuesday, September 27, 2005 9:24 AM
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] how to do 'deep queries'?
Anthony Molinaro wrote:
> that query is 100% correct.
>
> it's just an equijoin (a type of inner join) between 3 tables.
>
> the syntax you show is how queries should be written and is more
> representative of what a joins between relations really are:
> Cartesian products with filters applied
>
> the ansi syntax, the explicit JOIN ... ON stuff is (imho)
unnecessary,
> useful only for outer joins since all the vendors did it differently.
>
Whether you feel that is unnecessary or not, it *is* the ANSI Standard
and is thus, by definition, "how queries should be written."
In addition to cleaning up the outer join issue, it was added to make
the *intention* of the query clearer.
Because others are likely to read your query many more times than you
write it, clarity of intent *is* important.
> what you have will work for postgreSQL, I used the syntax you show in
my
> book
> for every single join recipe except for outjoins.
>
> are you seeing errors?
>
> regards,
> Anthony
[original snipped]
--
Daryl
"We want great men who, when fortune frowns, will not be discouraged."
-- Colonel Henry Knox, 1776
---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: how to do 'deep queries'?
@ 2005-09-27 15:35 Daryl Richter <daryl@brandywine.com>
parent: Anthony Molinaro <amolinaro@wgen.net>
0 siblings, 0 replies; 8+ messages in thread
From: Daryl Richter @ 2005-09-27 15:35 UTC (permalink / raw)
To: Anthony Molinaro <amolinaro@wgen.net>; +Cc: pgsql-sql
Anthony Molinaro wrote:
> Daryl,
>
>
>>Whether you feel that is unnecessary or not, it *is* the ANSI Standard
>
>
>>and is thus, by definition, "how queries should be written."
>
>
> I disagree 100%. Oracle and db2 introduced window functions years
> before
> Ansi added them. Should we not have used them? It absurd to avoid using
> a feature cuz it's not ansi.
>
Of course it would be absurd, I have not suggested otherwise. Joins are
not a *new* feature.
> Honestly, Don't be a slave to ansi, you miss out on all the great
> vendor specific functionality *that you're already paying for*
>
>
>>it was added to make the *intention* of the query clearer.
>
>
> More clearer to whom?
>
> Certainly not developers who have been working for many years
> using the old syntax.
>
> The intention of the old syntax is perfect. Realize that the problem is
> not the old syntax, the problem is the watered down database field
> today.
> I see this more and more with each interview I conduct looking
> for dba's and developers.
>
I generally agree with your assessment of the state of database
knowledge (particularly re developers). It is, however, the reality we
live in.
[snipped nostalgia and back-patting]
> I've never worked in a place that used ANSI only syntax and I've never
> had a problem with clarity nor any developers I've worked with.
> So, I don't at all get what you're saying...
> Old style is short and sweet and perfect.
> Ansi dumbed it down, that's the bottom line.
> And for people who've been developing for sometime,
> It's wholly unnecessary.
>
Well, perhaps you will one day and a developer will hose your server
with a "accidental" cross join and then you will understand.
But hopefully not. ;)
> Regards,
> Anthony
>
[rest snipped]
--
Daryl
Director of Technology
(( Brandywine Asset Management )
( "Expanding the Science of Global Investing" )
( http://www.brandywine.com ))
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: how to do 'deep queries'?
@ 2005-09-27 15:44 Anthony Molinaro <amolinaro@wgen.net>
0 siblings, 0 replies; 8+ messages in thread
From: Anthony Molinaro @ 2005-09-27 15:44 UTC (permalink / raw)
To: daryl@brandywine.com; +Cc: pgsql-sql
> Well, perhaps you will one day and a developer will hose your server
> with a "accidental" cross join and then you will understand.
Hehe :))
hey man, that's what testing and code review is all about
(dev teams still do that don't they?)
Accidental cartesians don't get to production ;)
Regards,
Anthony
-----Original Message-----
From: Daryl Richter [mailto:daryl@brandywine.com]
Sent: Tuesday, September 27, 2005 11:35 AM
To: Anthony Molinaro
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] how to do 'deep queries'?
Anthony Molinaro wrote:
> Daryl,
>
>
>>Whether you feel that is unnecessary or not, it *is* the ANSI
Standard
>
>
>>and is thus, by definition, "how queries should be written."
>
>
> I disagree 100%. Oracle and db2 introduced window functions years
> before
> Ansi added them. Should we not have used them? It absurd to avoid
using
> a feature cuz it's not ansi.
>
Of course it would be absurd, I have not suggested otherwise. Joins are
not a *new* feature.
> Honestly, Don't be a slave to ansi, you miss out on all the great
> vendor specific functionality *that you're already paying for*
>
>
>>it was added to make the *intention* of the query clearer.
>
>
> More clearer to whom?
>
> Certainly not developers who have been working for many years
> using the old syntax.
>
> The intention of the old syntax is perfect. Realize that the problem
is
> not the old syntax, the problem is the watered down database field
> today.
> I see this more and more with each interview I conduct looking
> for dba's and developers.
>
I generally agree with your assessment of the state of database
knowledge (particularly re developers). It is, however, the reality we
live in.
[snipped nostalgia and back-patting]
> I've never worked in a place that used ANSI only syntax and I've
never
> had a problem with clarity nor any developers I've worked with.
> So, I don't at all get what you're saying...
> Old style is short and sweet and perfect.
> Ansi dumbed it down, that's the bottom line.
> And for people who've been developing for sometime,
> It's wholly unnecessary.
>
Well, perhaps you will one day and a developer will hose your server
with a "accidental" cross join and then you will understand.
But hopefully not. ;)
> Regards,
> Anthony
>
[rest snipped]
--
Daryl
Director of Technology
(( Brandywine Asset Management )
( "Expanding the Science of Global Investing" )
( http://www.brandywine.com ))
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2005-09-27 15:44 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-09-27 00:34 how to do 'deep queries'? jeff sacksteder <jsacksteder@gmail.com>
2005-09-27 00:45 Re: how to do 'deep queries'? Stewart Ben (RBAU/EQS4) * <Ben.Stewart@au.bosch.com>
2005-09-27 00:58 Re: how to do 'deep queries'? Anthony Molinaro <amolinaro@wgen.net>
2005-09-27 03:35 ` jeff sacksteder <jsacksteder@gmail.com>
2005-09-27 13:24 ` Daryl Richter <daryl@brandywine.com>
2005-09-27 14:23 Re: how to do 'deep queries'? Anthony Molinaro <amolinaro@wgen.net>
2005-09-27 15:35 ` Daryl Richter <daryl@brandywine.com>
2005-09-27 15:44 Re: how to do 'deep queries'? Anthony Molinaro <amolinaro@wgen.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox