public inbox for [email protected]
help / color / mirror / Atom feedFrom: Isaac Morland <[email protected]>
To: Greg Sabino Mullane <[email protected]>
Cc: Rob Foehl <[email protected]>
Cc: [email protected]
Subject: Re: Finding "most recent" using daterange
Date: Wed, 22 May 2024 11:13:12 -0400
Message-ID: <CAMsGm5e5=YcjaUGQogkxMqrj9_beuSmVOrXTAuQPsBdmkbZPSA@mail.gmail.com> (raw)
In-Reply-To: <CAKAnmmLBxrQ0n4+BPb_xBQKrDRoiq4eSKdQYDbnmo7KTQVFuRg@mail.gmail.com>
References: <[email protected]>
<CAKAnmmLBxrQ0n4+BPb_xBQKrDRoiq4eSKdQYDbnmo7KTQVFuRg@mail.gmail.com>
On Wed, 22 May 2024 at 10:15, Greg Sabino Mullane <[email protected]>
wrote:
> This is a good candidate for a window function. Also note that nulls
> already get sorted correctly by the DESC so no need to get 'infinity'
> involved, although you could write 'DESC NULLS FIRST' to be explicit about
> it.
>
> with x as (select *, row_number() over (partition by id order by
> upper(dates) desc, lower(dates) desc) from example)
> select id,value,dates from x where row_number = 1;
>
Don’t you need NULLS LAST for the lower bounds? There NULL means something
closer to -infinity and should appear after the non-NULL values in a
descending sort.
Actually it strikes me that this sorting issue could be a reason to avoid
NULL bounds on ranges and prefer the use of +/-infinity if the underlying
data type supports it.
view thread (4+ messages) latest in thread
reply
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: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Finding "most recent" using daterange
In-Reply-To: <CAMsGm5e5=YcjaUGQogkxMqrj9_beuSmVOrXTAuQPsBdmkbZPSA@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox