Re: a wierd query - Mailing list pgsql-sql

From sad
Subject Re: a wierd query
Date
Msg-id 200405171112.49787.sad@bankir.ru
Whole thread Raw
In response to Re: a wierd query  ("Stijn Vanroye" <s.vanroye@farcourier.com>)
List pgsql-sql
> 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.



pgsql-sql by date:

Previous
From: "Freddy Villalba Arias"
Date:
Subject: problem with spanish characters
Next
From: "Stijn Vanroye"
Date:
Subject: Re: a wierd query