Re: a wierd query

From: sad <sad(at)bankir(dot)ru>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: a wierd query
Date: 2004-05-17 07:12:49
Message-ID: 200405171112.49787.sad@bankir.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stijn Vanroye 2004-05-17 07:25:52 Re: a wierd query
Previous Message Gaetano Mendola 2004-05-16 11:42:10 Re: How to speed up a time dimension query