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 1t86KL-0022SE-GX for pgsql-general@arkaria.postgresql.org; Mon, 04 Nov 2024 23:17:40 +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 1t86KI-0067rj-MM for pgsql-general@arkaria.postgresql.org; Mon, 04 Nov 2024 23:17:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t86KI-0067rX-BU for pgsql-general@lists.postgresql.org; Mon, 04 Nov 2024 23:17:38 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t86KG-000CmV-2x for pgsql-general@postgresql.org; Mon, 04 Nov 2024 23:17:37 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-7ea76a12c32so3657811a12.1 for ; Mon, 04 Nov 2024 15:17:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1730762254; x=1731367054; darn=postgresql.org; h=mime-version:subject:message-id:to:from:date:from:to:cc:subject :date:message-id:reply-to; bh=Pbe14tBFCOMX3ij8L7bvq8FfxGIZaMoxb6OJZQ5T0M8=; b=Cj8wJ4xO46pyh0MUaU5EuyF2Vn70vSXXBZoTbEv6kPbhTOsy6Syi0vjjsij9NuAPpe 3aZZxTip4DCVRmjE2xVU0j35MXe/57meb6DEExHTbDWK7b37BX8lmNDlJw0Bx9AUB1PT N3pXt+XuDB3fa+xZvze4vxU/9uoB/l112n7CBytR5sGYVhUeOxA6WE6nv4zlc4N6lVcg qP65NLx3t2LSdzbmuPyjJF5cfxSR4WPDenTkSFuVqNj9kvGaEo9vQ9TDke84d4qdO/NT AlZjj8nu1TS4TLBFYme7lDJ4LMEbkcb2QFNrCu7wT5A2cjq1kyYc2eOzYKEBzqwi72S3 EfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730762254; x=1731367054; h=mime-version:subject:message-id:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=Pbe14tBFCOMX3ij8L7bvq8FfxGIZaMoxb6OJZQ5T0M8=; b=q5e0IrXEUyizItvLHRWvc55ggVF+eGJGAJ/CIIgVDsO8wI57VZ46RVBadyFkEY+gE6 PYVR2AHVAX0tPX1/AKb3Ni5S/rH7B1U1P146jA4u/SjJ9Pf+M6P0BFyLfw/OufeSX679 EleXoUfnSXCbhnPVb+VB+n15HNXeHjG19pV27J32YuOMt0MvRMDeF+mAmTMR5CN68iMQ T56viBT3zoBVtuhNOtfqmuV38pHEcFqcZafFB1y7LSylpbMCiWrLhLja8d+3m6+XHeEx WX2aUxxNQLpsIlIOMaRlSXLLj6gkjvSy1UVxkwVpJn8Xfc4uLih8vqTs+xQV+vU98nHk Ob2A== X-Gm-Message-State: AOJu0YzSYLSm4KPIc7/JL7l0D6ouG3wswCdaNWGiXnGc3dqcRji5juOA EWow38oj1LnCeHEqkBsopTdB4nx6YZD/uJStPwU2K3tznYaFGkiQvMQ9Pmdo X-Google-Smtp-Source: AGHT+IG5d7NYxQU5dIggMbP2Zb45hhh3ZdSOUtgkJfyLt0PxucWSDXxcE6Ertpj2jf2hIBwMeZLo4Q== X-Received: by 2002:a17:90b:52c8:b0:2e2:a013:859a with SMTP id 98e67ed59e1d1-2e93c128a9cmr23423694a91.7.1730762254388; Mon, 04 Nov 2024 15:17:34 -0800 (PST) Received: from [2600:8801:8600:3d2:709c:6101:300:0] ([2600:8801:8600:3d2::9]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e93dac0479sm8289993a91.33.2024.11.04.15.17.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Nov 2024 15:17:33 -0800 (PST) Date: Mon, 4 Nov 2024 15:17:16 -0800 From: Guyren Howe To: PG-General Mailing List Message-ID: <3ed0759d-c332-4f96-a147-499a694e9204@Spark> Subject: nth_value out of more than n values returns null X-Readdle-Message-ID: 3ed0759d-c332-4f96-a147-499a694e9204@Spark MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="6729560c_2b509be4_11af" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --6729560c_2b509be4_11af Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline This query: SELECT NTH_VALUE(id, 5000000) OVER (ORDER BY created_at, id ASC) FROM table in a table where SELECT COUNT(*) returns a value a few thousand over 5 million, where id is the primary key, returns null. The inclusion of the primary key should make the order by a total order. So there should be a 5 millionth row. How can this happen? --6729560c_2b509be4_11af Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
This query:

SE= LECT NTH=5FVALUE(id, 5000000) OVER (ORDER BY created=5Fat, id ASC) =46ROM= table

in a table where SELECT COUNT(*) retu= rns a value a few thousand over 5 million, where id is the primary key, r= eturns null.

The inclusion of the primary ke= y should make the order by a total order. So there should be a 5 milliont= h row.

How can this happen=3F
--6729560c_2b509be4_11af--