Re: No sort with except

Поиск
Список
Период
Сортировка
От Frank Lanitz
Тема Re: No sort with except
Дата
Msg-id 4F4F3075.3030506@frank.uvena.de
обсуждение исходный текст
Ответ на No sort with except  (reto.buchli@wsl.ch)
Ответы Re: No sort with except  (reto.buchli@wsl.ch)
Список pgsql-sql
Am 01.03.2012 09:13, schrieb reto.buchli@wsl.ch:
> Dear all,
> 
> When I run the following SQL with PostgreSQL 9.1:
> 
> -- 
> SELECT DISTINCT ON (pernr) pernr, vorna, nachn, eindt, ausdt, updat, status
>   FROM person
>        
> WHERE eindt <= TO_CHAR(CURRENT_DATE,'YYYYMMDD')
>         AND ausdt >= TO_CHAR(CURRENT_DATE,'YYYYMMDD')
> 
> ORDER BY pernr, eindt DESC;
> -- 
> 
> it works. I get the most recent persons, even if one came back within
> this time range.
> 
> But if i do this:
> 
> ---
> SELECT DISTINCT ON (pernr) pernr, vorna, nachn, eindt, ausdt, updat, status
>   FROM person
>        
> WHERE eindt <= TO_CHAR(CURRENT_DATE,'YYYYMMDD')
>         AND ausdt >= TO_CHAR(CURRENT_DATE,'YYYYMMDD')
> EXCEPT        
> 
> SELECT DISTINCT ON (pernr) pernr,  vorna, nachn, eindt, ausdt, updat,
> status
>   FROM person
>        RIGHT JOIN table ON sobid = CAST (pernr AS VARCHAR) AND objid = 10
> WHERE eindt <= TO_CHAR(CURRENT_DATE,'YYYYMMDD')
>         AND ausdt >= TO_CHAR(CURRENT_DATE,'YYYYMMDD')
> ORDER BY pernr, eindt DESC;
> ---
> 
> In this case the ORDER BY does not work: I will get the same person
> data, either with DESC as with ASC, even when this should change.
> 
> Does anyone have an explanation for this?


Don't you sort just the part at EXCEPT?

Cheers,
Frank



В списке pgsql-sql по дате отправления:

Предыдущее
От: reto.buchli@wsl.ch
Дата:
Сообщение: No sort with except
Следующее
От: reto.buchli@wsl.ch
Дата:
Сообщение: Re: No sort with except