X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6539ED1BADF for ; Mon, 17 May 2004 05:06:40 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 91695-02 for ; Mon, 17 May 2004 05:06:21 -0300 (ADT) Received: from rock.spider.ru (rock.spider.ru [62.183.34.226]) by svr1.postgresql.org (Postfix) with ESMTP id 03B9CD1BAD3 for ; Mon, 17 May 2004 05:06:18 -0300 (ADT) Received: from rock (localhost [127.0.0.1]) by rock (Postfix) with SMTP id B4B64912AC for ; Mon, 17 May 2004 12:06:13 +0400 (MSD) Received: from sad.localnet.ru (sad.localnet.ru [10.0.0.33]) by rock.spider.ru (Postfix) with ESMTP id 9E451911EB for ; Mon, 17 May 2004 12:06:12 +0400 (MSD) Content-Type: text/plain; charset="iso-8859-1" From: sad Organization: IT To: pgsql-sql@postgresql.org Subject: Re: a wierd query Date: Mon, 17 May 2004 11:12:49 +0400 User-Agent: KMail/1.4.3 References: <71E201BE5E881C46811BA160694C5FCB0FA94F@fs1000.farcourier.com> In-Reply-To: <71E201BE5E881C46811BA160694C5FCB0FA94F@fs1000.farcourier.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200405171112.49787.sad@bankir.ru> X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/143 X-Sequence-Number: 17857 > I forgot one situation: > > if I run the query like so: > select distinct on (task_id, begindate) task_id, workhour_id, > begindate as date from workhour UNION > select distinct on (task_id, enddate) task_id, workhour_id, enddate > as date from workhour I get yet another value: 2961 rows. > > So I got 3 different result sets for 3 different ways to run the query. > Even in this last case the UNION doesn't seem to only return unique value= s, > and I will still need the top-level select. if we suppose this situation possible to program in SQL it causes data-loss in query (i mean unpredictable query result: if you have two records (f=3D1,b=3D2),(f=3D1,b=3D3) "distinct ON f" makes a value of b meaningless) So you MUST NOT select that way P.S. This situation means: you have wrong data structure.=20