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 1twZMX-00FePd-F7 for pgsql-general@arkaria.postgresql.org; Mon, 24 Mar 2025 04:24:33 +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 1twZMW-00CGtM-4v for pgsql-general@arkaria.postgresql.org; Mon, 24 Mar 2025 04:24:32 +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 1twZMV-00CGtE-Q0 for pgsql-general@lists.postgresql.org; Mon, 24 Mar 2025 04:24:31 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1twZMT-000nIS-1F for pgsql-general@lists.postgresql.org; Mon, 24 Mar 2025 04:24:31 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-2c7e5fb8c38so238961fac.1 for ; Sun, 23 Mar 2025 21:24:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742790267; x=1743395067; darn=lists.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=swTdE/F2nO+28o7CslqHcgtQIVFgMaqnlyUx3XLDmNA=; b=UQ7ncXQdWmilfX5h9SD5VW6fseegk7GCH31ylnaJnsi25MeFmjPVoh4rTV+ptGOj9A oD5XVJgZEmVdiSZD99izL4jffxIEeOK/Vrk4O4W9qv8Y0wRKjAViWmXBAtm32DxBhBDS FfFINcZrJDTjQk/BDLhYfMzf9RgAI4wdqu9G6vDXwwJijcaXLzQBlZEIZIP+U2Ee8mj8 tXsCCgpgJq86fUHW04RM0S69rNI3rY4a9MkA5KlcWVB/ahRx/X1le5IftRhyBwWhQ+78 FRhFFWa2orOwtL70gz9DhnmBxW24AVq05V4jSI8X9qqI7jumDzZJQcio+bxkMyK5PSRq qU3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742790267; x=1743395067; 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=swTdE/F2nO+28o7CslqHcgtQIVFgMaqnlyUx3XLDmNA=; b=j5CpmAASWBI9QVhVulRVhKrSNX1VCMhxlfPXEbIMma8BAhzluQ2ssc/h7Ss9bj6NQF uPVP73WiHvqeIczTI5gTnYEXwDB+8xE6XUpuV1xQXzPIcrbAcpfIiY+oAywH0ScUSI0E T/aDF3i+m5tzJL6jxAT1clLtkzRm1yuoPRqypMkaNbbCuB+r0wzuPknpuQrLKsy1SV5o /1rftpQ3gm/fqqiVyh2PuZfy7Doww+BWcQe7YcArEr3R3uJz4Ffruar0hrgaGNtGkgjO hmNh6W+kj0DzyFbkIt58Cpw5vPzvJzcMsbZ43tiAigMo24iX4gl8YTilJndTPxpA2JOd hl2w== X-Forwarded-Encrypted: i=1; AJvYcCXd9Hv7Zb4CRpbNuGyI2CwYG3Kh7ijSXC09L/C7RgKGZoHFOfLWDt6SMiMKjikwPsFZHdqhjKRzRHnOYF32@lists.postgresql.org X-Gm-Message-State: AOJu0Ywra0DMrMEAj4FPKyk+96Dx3f+nmprow75OwdZzXP1W73SU2A4b W1A9FLlhW1rDT4jppld7jJK5Wm/q0z2G66g0Ki6xcv1YibinjXbcJuPYEBaPfbuTlbRLjo9wDEV gkGWGWCHfXUZSUgTgrt4gZ4m9dSA= X-Gm-Gg: ASbGncvyTUJhJUob2OUS9vvf/STa4o3wTn61pA5XtE0dquiZODiQeZSNILxrlrafj12 5vuxGI5QUq0UqDlm2TB+XtiukAjxTZTQNSW04AOuCLPTDLofITJlRvXi4yL7HkJF8LGLKTCCsjQ pXvktZgO43YEH/w7NHWsqA/Sib X-Google-Smtp-Source: AGHT+IF8XA/oTL5NEtZEI12pBPmxYokGDA0GutiQzrE3mNwCuE0mWQL/Rxx4X6bfG7f6bDwpA/sBNa+a378uNfi1bWU= X-Received: by 2002:a05:6870:2f01:b0:29e:4340:b1b with SMTP id 586e51a60fabf-2c78022c095mr7497278fac.9.1742790267001; Sun, 23 Mar 2025 21:24:27 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a8a:349:0:b0:589:13f9:e937 with HTTP; Sun, 23 Mar 2025 21:24:26 -0700 (PDT) In-Reply-To: <691954B8-AB7C-4A7D-904A-79547BDC364F@thebuild.com> References: <691954B8-AB7C-4A7D-904A-79547BDC364F@thebuild.com> From: "David G. Johnston" Date: Sun, 23 Mar 2025 21:24:26 -0700 X-Gm-Features: AQ5f1Jo0_cwHnDeaS37GPJa1SmARTtSqzzqNiJd4r7hUPVsb2QCIqyW3QyeJOYE Message-ID: Subject: Re: Best way to check if a table is empty To: Christophe Pettus Cc: Marcelo Fernandes , "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="000000000000c866c706310efa36" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000c866c706310efa36 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sunday, March 23, 2025, Christophe Pettus wrote: > > (And to be pedantic, #1 returns TRUE / FALSE while #2 returns / > NULL, so they aren't exactly equivalent. If you are able to handle = / > NULL, you don't need the EXISTS clause.) > Leaving the limit in place, without exists #1 returns either an empty set or an , never NULL. Always returning a Boolean seems like a better API choice though; but standardizing on that final transform doesn=E2=80=99t change the base compa= rison. David J. --000000000000c866c706310efa36 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sunday, March 23, 2025, Christophe Pettus <xof@thebuild.com> wrote:

(And to be pedantic, #1 returns TRUE / FALSE while #2 returns <int> /= NULL, so they aren't exactly equivalent.=C2=A0 If you are able to hand= le <int> / NULL, you don't need the EXISTS clause.)

Leaving the limit in place, without exists= #1 returns either an empty set or an <int>, never NULL.
Always returning a Boolean seems like a better API choice thou= gh; but standardizing on that final transform doesn=E2=80=99t change the ba= se comparison.

David J.

--000000000000c866c706310efa36--