Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Stefan Schwarzer
You may also wish to review Andreas' suggestions as they propose a more sensible table structure rather than having a table for each convention. The table proposal really looks nice. But our database is structured by variable - so each convention has its own table. It is a really bad design -

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread A. Kretschmer
In response to A. Kretschmer : > In response to Thom Brown : > > On 23 February 2010 13:43, Stefan Schwarzer > > wrote: > > Select countries.name, basel.year, basel.value, cites.year, cites.value > > From countries > > Left Join basel on basel.id_country = countries.id_country and >

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread A. Kretschmer
In response to Thom Brown : > On 23 February 2010 13:43, Stefan Schwarzer > wrote: > Select countries.name, basel.year, basel.value, cites.year, cites.value > From countries > Left Join basel on basel.id_country = countries.id_country and > basel.value=1 > Left Join cites

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Stefan Schwarzer
Select countries.name, basel.year, basel.value, cites.year, cites.value From countries Left Join basel on basel.id_country = countries.id_country and basel.value=1 Left Join cites on cites.id_country = countries.id_country and cites.value=1 I would have thought so, but the query turns forever.

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread A. Kretschmer
In response to Stefan Schwarzer : > >You may also wish to review Andreas' suggestions as they propose a > >more sensible table structure rather than having a table for each > >convention. > > The table proposal really looks nice. But our database is structured > by variable - so each convention

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Thom Brown
On 23 February 2010 13:43, Stefan Schwarzer wrote: Select countries.name, basel.year, basel.value, cites.year, cites.value From countries Left Join basel on basel.id_country = countries.id_country and basel.value=1 Left Join cites on cites.id_country = countries.id_country

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Stefan Schwarzer
Select countries.name, basel.year, basel.value, cites.year, cites.value From countries Left Join basel on basel.id_country = countries.id_country and basel.value=1 Left Join cites on cites.id_country = countries.id_country and cites.value=1 I would have thought so, but the query turns forever.

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Thom Brown
On 23 February 2010 13:23, Stefan Schwarzer wrote: >> Select countries.name, basel.year, basel.value, cites.year, cites.value >> From countries >> Left Join basel on basel.id_country = countries.id_country and >> basel.value=1 >> Left Join cites on cites.id_country = countries.id_country and >> ci

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Stefan Schwarzer
Select countries.name, basel.year, basel.value, cites.year, cites.value From countries Left Join basel on basel.id_country = countries.id_country and basel.value=1 Left Join cites on cites.id_country = countries.id_country and cites.value=1 I would have thought so, but the query turns fore

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread A. Kretschmer
In response to Stefan Schwarzer : > Hi there, > > gush, shouldn't be that complicated. But neither in Postgres, nor in Access I > succeed in getting the result I wish. > > I have a couple of times for the Environmental Conventions (Kyoto, Montreal, > CITES etc.). They look like this: > > id_coun

Re: [GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Thom Brown
On 23 February 2010 11:44, Stefan Schwarzer wrote: > Hi there, > gush, shouldn't be that complicated. But neither in Postgres, nor in Access > I succeed in getting the result I wish. > I have a couple of times for the Environmental Conventions (Kyoto, Montreal, > CITES etc.). They look like this:

[GENERAL] Subqueries or Joins? Problems with multiple table query

2010-02-23 Thread Stefan Schwarzer
Hi there, gush, shouldn't be that complicated. But neither in Postgres, nor in Access I succeed in getting the result I wish. I have a couple of times for the Environmental Conventions (Kyoto, Montreal, CITES etc.). They look like this: id_country,year,value 4,1992,0 4,1993,0 4,1994,0 4,1

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-06 Thread Bruce Momjian
Tom Lane wrote: > "Richard Broersma" <[EMAIL PROTECTED]> writes: > > I am curious if the motivation is still valid for intentionally > > omitting check sub-queries. (what was the motivation to begin with?) > > > Since we can effectively work around this limitation by doing the same > > thing with

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Tom Lane
Jeff Davis <[EMAIL PROTECTED]> writes: > On Tue, 2008-09-02 at 19:22 -0400, Tom Lane wrote: >> Jeff Davis <[EMAIL PROTECTED]> writes: >>> My question is not why don't we allow subqueries in CHECK, my question >>> is why do we allow stable/volatile functions? >> >> Historically we've allowed it, >

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Richard Broersma
On Tue, Sep 2, 2008 at 3:47 PM, Alvaro Herrera <[EMAIL PROTECTED]> wrote: > The problem is that you have to rerun the query to verify that the CHECK > condition still holds, whenever the table that the CHECK clause is > checking changes. This is rather problematic, because we'd need to make > the

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Jeff Davis
On Tue, 2008-09-02 at 19:22 -0400, Tom Lane wrote: > Jeff Davis <[EMAIL PROTECTED]> writes: > > My question is not why don't we allow subqueries in CHECK, my question > > is why do we allow stable/volatile functions? > > Historically we've allowed it, and it's not clear what we'd buy by > changing

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Jeff Davis
On Tue, 2008-09-02 at 18:57 -0400, Tom Lane wrote: > The standard says that the constraint is guaranteed not to be violated, > which in the worst case means that any time you update the table(s) > referenced in the subquery, you have to retest the CHECK expression > at every row of the table having

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Tom Lane
Jeff Davis <[EMAIL PROTECTED]> writes: > My question is not why don't we allow subqueries in CHECK, my question > is why do we allow stable/volatile functions? Historically we've allowed it, and it's not clear what we'd buy by changing that, other than breaking existing applications whose authors

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Jeff Davis
On Tue, 2008-09-02 at 18:47 -0400, Alvaro Herrera wrote: > The problem is that you have to rerun the query to verify that the CHECK > condition still holds, whenever the table that the CHECK clause is > checking changes. This is rather problematic, because we'd need to make > the system aware of s

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Jeff Davis
On Tue, 2008-09-02 at 15:30 -0700, Richard Broersma wrote: > I am curious if the motivation is still valid for intentionally > omitting check sub-queries. (what was the motivation to begin with?) > > Since we can effectively work around this limitation by doing the same > thing with a function in

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Tom Lane
"Richard Broersma" <[EMAIL PROTECTED]> writes: > I am curious if the motivation is still valid for intentionally > omitting check sub-queries. (what was the motivation to begin with?) > Since we can effectively work around this limitation by doing the same > thing with a function in a CHECK constr

Re: [GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Alvaro Herrera
Richard Broersma escribió: > I am curious if the motivation is still valid for intentionally > omitting check sub-queries. (what was the motivation to begin with?) The problem is that you have to rerun the query to verify that the CHECK condition still holds, whenever the table that the CHECK clau

[GENERAL] Subqueries in Check() -- Still Intentionally Omitted?

2008-09-02 Thread Richard Broersma
I am curious if the motivation is still valid for intentionally omitting check sub-queries. (what was the motivation to begin with?) Since we can effectively work around this limitation by doing the same thing with a function in a CHECK constraint, why would we want to prevent anyone from using th

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread Demel, Jeff
I just wanted to say thanks to everyone for your help. -Jeff This email is intended only for the individual or entity to which it is addressed. This email may contain information that is privileged, confidential or otherwise protected from disclosure. Dissemination, distribution or copying of

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread Tom Lane
"Demel, Jeff" <[EMAIL PROTECTED]> writes: > Here's what I came up with: > SELECT customers.id, customers.firstname, > customers.lastname, customers.phone number, > (SELECT ar.billdate FROM ar > WHERE customers.customerid = ar.customerid > ORDER BY ar.billdate LIMIT 1) > AS l

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread Demel, Jeff
, 2007 11:09 AM To: Demel, Jeff; pgsql-general@postgresql.org Subject: RE: [GENERAL] Subqueries - performance and use question sorry, missing GROUP BY and some column naming was messed up but hopefully you get the idea: SELECT c.id, c.firstname, c.lastname, a.latest_billdate FROM customers c

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread George Pavlov
ql-general@postgresql.org > Subject: Re: [GENERAL] Subqueries - performance and use question > > try this approach: > > SELECT > c.id, > c.firstname, > c.lastname, > a.latest_billdate > FROM > customers c > INNER JOIN -- or LEFT if you want the NU

Re: [GENERAL] Subqueries - performance and use question

2007-02-01 Thread George Pavlov
7;new'; > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Demel, Jeff > Sent: Thursday, February 01, 2007 8:08 AM > To: pgsql-general@postgresql.org > Subject: [GENERAL] Subqueries - performance and use question > > I ne

[GENERAL] Subqueries - performance and use question

2007-02-01 Thread Demel, Jeff
I need some basic advice on how to run a subquery, or if there's a better way. Let me set up a situation, and get some advice on it. This is my first post on this list, so I hope this kind of noob question is ok. Say I have a table of customers and table of accounts receivable transactions, The

Re: [GENERAL] Subqueries

2005-11-06 Thread Thomas F. O'Connell
On Nov 6, 2005, at 3:19 PM, Bob Pawley wrote: Last week I received help form the list in inserting a serial row of one table (process) into a row in a table called specification. I was able to expand that to include inserting the same information into a table called pipe.

[GENERAL] Subqueries

2005-11-06 Thread Bob Pawley
Last week I received help form the list in inserting a serial row of one table (process) into a row in a table called specification.   I was able to expand that to include inserting the same information into a table called pipe. --- create or replace function base() returns

Re: [GENERAL] subqueries

2005-06-20 Thread Tomasz Grobelny
On Monday 20 of June 2005 00:12, you wrote: > I have such a statement: > select * from (subquery1) as foo, (subquery2) as bar; > Both subqueries are reasonably fast (<0.5s) and generate results that have > several (<10) rows but the whole query takes forever to execute. Ok, postgresql wanted to be

Re: [GENERAL] subqueries

2005-06-20 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2005-06-20 01:02:38 +0200: > I wanted to define a function like this: > create or replace function fun(...)... > create temp table qaz as subquery1; > create temp table wsx as subquery1; > select * from qaz, wsx; > language sql; > but I get postgresql error saying that relatio

Re: [GENERAL] subqueries

2005-06-19 Thread Tom Lane
Tomasz Grobelny <[EMAIL PROTECTED]> writes: > I have such a statement: > select * from (subquery1) as foo, (subquery2) as bar; > Both subqueries are reasonably fast (<0.5s) and generate results that have > several (<10) rows but the whole query takes forever to execute. The above is an unconstrai

Re: [GENERAL] subqueries

2005-06-19 Thread Tomasz Grobelny
On Monday 20 of June 2005 00:35, you wrote: > - Original Message - > From: "Tomasz Grobelny" <[EMAIL PROTECTED]> > To: > Sent: Sunday, June 19, 2005 6:12 PM > Subject: [GENERAL] subqueries > > >I have such a statement: > > select * from (s

Re: [GENERAL] subqueries

2005-06-19 Thread Sean Davis
- Original Message - From: "Tomasz Grobelny" <[EMAIL PROTECTED]> To: Sent: Sunday, June 19, 2005 6:12 PM Subject: [GENERAL] subqueries I have such a statement: select * from (subquery1) as foo, (subquery2) as bar; Both subqueries are reasonably fast (<0.5s) a

[GENERAL] subqueries

2005-06-19 Thread Tomasz Grobelny
I have such a statement: select * from (subquery1) as foo, (subquery2) as bar; Both subqueries are reasonably fast (<0.5s) and generate results that have several (<10) rows but the whole query takes forever to execute. Moreover if I simplify those subqueries (limiting functionality) the whole sel

Re: [GENERAL] subqueries and qualification of table names

2005-04-26 Thread Tom Lane
Kevin Murphy <[EMAIL PROTECTED]> writes: > ... In the following query, PG treats the phrase "and chromosome > = chromosome" as "and genetic.chromosome = genetic.chromosome". And that surprises you why? regards, tom lane ---(end of broadcast)--

[GENERAL] subqueries and qualification of table names

2005-04-26 Thread Kevin Murphy
I have a query which didn't work properly until I fully qualified columns used in a a subquery with the appropriate table names. The reason is that both tables have a column named 'chromosome' used in the subquery. In the following query, PG treats the phrase "and chromosome = chromosome" as

[GENERAL] Subqueries failing inside pl/pgsql fuction called by trigger

2004-04-07 Thread Bob
Hi, I have a very odd postgresql problem. I have some subqueries contained within a function which are looking for unrefernced data and then delete any rows that are found: CREATE OR REPLACE FUNCTION housekeeping() RETURNS TRIGGER AS ' BEGIN DELETE FROM properties WHERE NOT EXISTS (SELECT

Re: [GENERAL] subqueries vs. separate queries

2004-01-29 Thread Guy Fraser
CSN wrote: Is there much difference between using subqueries and separating out them into separate queries? That would depend on what results your expecting, and how you intend on using the results. For example if you want all the data in a single statement, you can't break it up, but the req

[GENERAL] subqueries vs. separate queries

2004-01-29 Thread CSN
Is there much difference between using subqueries and separating out them into separate queries? __ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/ ---(end of broadcast)