Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t86t8-0025x0-T3 for pgsql-general@arkaria.postgresql.org; Mon, 04 Nov 2024 23:53:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t86t5-006ciu-Ic for pgsql-general@arkaria.postgresql.org; Mon, 04 Nov 2024 23:53:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t86t5-006cil-5P for pgsql-general@lists.postgresql.org; Mon, 04 Nov 2024 23:53:35 +0000 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t86t2-000DzZ-2S for pgsql-general@postgresql.org; Mon, 04 Nov 2024 23:53:35 +0000 Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-5ebbfcab9f4so2447122eaf.2 for ; Mon, 04 Nov 2024 15:53:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730764411; x=1731369211; darn=postgresql.org; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=3/QRRTtlj+Z4s05iIsOirmo4MAoDZ7iO0TVuX4kEAcY=; b=MhC1r2uJBlPuN79EenOs4b9viw3LOIdP6LygtYk0G6q0G989XGDZBnyN9gxTmJ4GHd Xxmo49TZhMLVGFEOqSJ40c0nMTn8H+cPhpD0H6Bvl55oZZIfMDO437L7xVGs8LUkxYlK MbSIOQ2qTrpGaBpZEbeMJ4zGpO6WxrIitsFrgjdeVjQXd7qIx3M1pF+/SztYUr1Ae+kS qNU2iTx6XBzGuyiWlCTemzyPDkEHxJiIGQcsZJ9tuEU/gm9Rgccw/uc/Vy8xgxguCQ6g iUKGAxf41mX3EzJrSbT0SDBf2tEBrhg/+NQYCs22tvvXLnVSouHyHX64PwdSDDq3WnWg fA6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730764411; x=1731369211; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3/QRRTtlj+Z4s05iIsOirmo4MAoDZ7iO0TVuX4kEAcY=; b=aYxBiuSPijgDJpKbbrTEkBAxulR9BXse+n648QWf+NW1cQhXLYm0Eu5UANNZnT8V// VxyX6Efi4HQzQYQhVl2509BgJ1aIhXdeHgEqMVy39AL9d3IZjormtjNQIf/Vg84jMzFU kcHnBwLZ2Gt1DLBsjh4U94LBNKfX4KiSSd5HzqeXo3fJr8mFTbH1T1rmlrj5Rahklznn TVsVF9a8VyL+S5Irtv6eJ7wIdRBT66KRalNyJUvkk84Qnlk4SJ/TSV2v8mj+mC8X5m89 W+cfVe5bFe2jVnm3OntAXpB/8YjLS5ycsSblSSd2gwyLIzV04OJvwcYEcEfiZiJ5mh35 cvaQ== X-Forwarded-Encrypted: i=1; AJvYcCVMLE2qav/aEOaHmtEKNgrFV45lNjXJGB7wglq6Pia1rHY688Wg2XHSVLBFGSfweyqUuj/b/hb8GhE1j7IZ@postgresql.org X-Gm-Message-State: AOJu0Yw/WQ/iZkWxAHNN42nlRkE1m5ViJzNNWlZ5f0tCUJWgpzmgdRnN UbBAfAv9YCCxoAKv1atqXZvthYpHI4JNhs1pNSCBojrwnll69pAqlwqDcDyad0fOhPOkpBBDueM dBfhO3qxiBx0EL1qCZ9G4UIm3pnM= X-Google-Smtp-Source: AGHT+IEzA8tIUTA1pqrVWeFpNUPZBsNLWt5S2V14YpXP+BRbN0kyMVHjw/EFxyD6QbRtY9PQKYnuwb8kwuzdYsem9iw= X-Received: by 2002:a05:6871:68d:b0:277:ed4b:a098 with SMTP id 586e51a60fabf-294844bd1a1mr13349053fac.20.1730764411085; Mon, 04 Nov 2024 15:53:31 -0800 (PST) MIME-Version: 1.0 Received: by 2002:ac9:53c8:0:b0:56c:c9af:3ee6 with HTTP; Mon, 4 Nov 2024 15:53:30 -0800 (PST) In-Reply-To: <34536f21-801c-41cb-a5ba-5389ce8201d0@Spark> References: <3ed0759d-c332-4f96-a147-499a694e9204@Spark> <56c4c567-8422-4944-81d1-2a3c2ac5c8fa@ewie.name> <4e60ede0-86a5-4900-b415-05d68ad75cb1@Spark> <34536f21-801c-41cb-a5ba-5389ce8201d0@Spark> From: "David G. Johnston" Date: Mon, 4 Nov 2024 16:53:30 -0700 Message-ID: Subject: Re: nth_value out of more than n values returns null To: Guyren Howe Cc: Erik Wienhold , PG-General Mailing List Content-Type: multipart/alternative; boundary="000000000000e9ab6d06261efd97" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e9ab6d06261efd97 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Monday, November 4, 2024, Guyren Howe wrote: > Wouldn=E2=80=99t it be offset 4_999_999? > Probably. I tend to expect off-by-one for these kinds of things and test my way out. > > I=E2=80=99d still like to understand why nth_value doesn=E2=80=99t work. > When you perform an order by in a window clause the frame you get by default ends at the current row. Consider =E2=80=9Ccount(*) over ()=E2=80= =9D versus =E2=80=9Ccount(*) over (order by id)=E2=80=9D. You need to not use defaults for the window frame if this doesn=E2=80=99t s= uit you. David J. --000000000000e9ab6d06261efd97 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Monday, November 4, 2024, Guyren Howe <guyren@gmail.com> wrote:
Wouldn=E2=80=99t it be offset 4_999_999?

Probably.=C2=A0 I tend to expect off-by-o= ne for these kinds of things and test my way out.
=C2=A0

I=E2=80=99d still like to understand why nth_value doesn=E2=80=99t work.

When you perform an order b= y in a window clause the frame you get by default ends at the current row.= =C2=A0 Consider =E2=80=9Ccount(*) over ()=E2=80=9D versus =E2=80=9Ccount(*)= over (order by id)=E2=80=9D.

You need to not use = defaults for the window frame if this doesn=E2=80=99t suit you.
<= br>
David J.

--000000000000e9ab6d06261efd97--