From: sad <sad@bankir.ru>
To: pgsql-sql@postgresql.org
Subject: Re: a wierd query
Date: Mon, 17 May 2004 11:12:49 +0400
Message-ID: <200405171112.49787.sad@bankir.ru> (raw)
In-Reply-To: <71E201BE5E881C46811BA160694C5FCB0FA94F@fs1000.farcourier.com>
References: <71E201BE5E881C46811BA160694C5FCB0FA94F@fs1000.farcourier.com>
> 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 values,
> 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=1,b=2),(f=1,b=3)
"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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: sad@bankir.ru
Subject: Re: a wierd query
In-Reply-To: <200405171112.49787.sad@bankir.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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