Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNiLR-0007JH-Cn for pgsql-general@arkaria.postgresql.org; Mon, 15 Aug 2022 22:14:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oNiLP-00014Q-JP for pgsql-general@arkaria.postgresql.org; Mon, 15 Aug 2022 22:13:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNiLP-00014G-68 for pgsql-general@lists.postgresql.org; Mon, 15 Aug 2022 22:13:59 +0000 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oNiLJ-0002ny-GL for pgsql-general@lists.postgresql.org; Mon, 15 Aug 2022 22:13:58 +0000 Received: by mail-pj1-x102f.google.com with SMTP id c19-20020a17090ae11300b001f2f94ed5c6so16585pjz.1 for ; Mon, 15 Aug 2022 15:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:from:to:cc; bh=OgyriqRYUdaPrNvjU9nEhtjU2pOslOtFMDEDC72/jFw=; b=UM/oHJYQ7TI7JNf7wLaoLIkURYuMFr3ejXGpV444v+0a/2Ns+sQGT01u761XZ8C+zU 6nzXoffXY08BDuncea7gE/AKfFEY00BI+frus1n430cNqPphYLVLr/ZuKKAMVpyi0728 DUDNjwoQmtRe8NDZzzr5ItjFHdXtbmTL04Ax7CUujWeMAZyYIl0RNhCI2tpfF8Vaxu9W Bp3JMK6DjQVyYTPA5oKK86ThS3p5NmHDUlESCE12EGwvQp3745mAcRgW6SpJI7lsc6/L EAf7N/7gRXo/I37eAQXLNSIkOkxFEpNLBxR0OEO9u/4eSkjMfw0LX65KKGjsYxcyP0P9 o6Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc; bh=OgyriqRYUdaPrNvjU9nEhtjU2pOslOtFMDEDC72/jFw=; b=B7SFJHvDC8nF9UF39X76Ai2cVQf/uOXLLPvqPE10x2n+yYMIXV9kBwp3iaqkQ7/W4c vNXsWmwYLQB9t+8hFtwlUcaIF+ZZg9dEGj6j7ipT0MrlTpEEli9EbTVW7rKVP1jLEeIL JYHVDmGfwE4ha+go3ZjsqvNq54AbfO3vawLv6R5jLwN2PTUfLb0Rzg8M6NBxggYx3Egi ReIzr6AKyPp+jjRfXyn1vwN94WhInQQ5B1m7nktuadq2E9+WSWE+9qjPodUKlvlmJNEk sGM4tzYjzo90Rj13/LxuIQpYICnzrj1kfUWtpmya8Awrn/LMvATBdNT3llAV6Fe0vDDO ruiQ== X-Gm-Message-State: ACgBeo0OOfynedaFsPtJ7SlJCUY958NepzfvXDvvW+eHDN8iIdjdgiRh O6dGcKslzObUeDa0fN3+1f9Yle7/cUg= X-Google-Smtp-Source: AA6agR7f8CjJ6Pv59/s67XkcsRqAIH4mrnpM5OE1OxKVGLwUMJfsmtwNJG4iVamKxqilaqlmA5L/VQ== X-Received: by 2002:a17:90b:2687:b0:1f7:362a:2d08 with SMTP id pl7-20020a17090b268700b001f7362a2d08mr19991396pjb.218.1660601631908; Mon, 15 Aug 2022 15:13:51 -0700 (PDT) Received: from [10.128.56.11] ([155.98.131.3]) by smtp.gmail.com with ESMTPSA id a20-20020aa79714000000b0052d2cd99490sm7007032pfg.5.2022.08.15.15.13.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Aug 2022 15:13:50 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------DUmTSo5DA082MlRHWvZ68m88" Message-ID: Date: Mon, 15 Aug 2022 16:13:49 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Subject: Re: ***SPAM*** Re: Can I get the number of results plus the results with a single query? Content-Language: en-CA To: pgsql-general@lists.postgresql.org References: <75BBE3C5-D495-47B8-A81C-6359391E3B99@easesoftware.com> <8D4B16FB-BE56-446E-BDE5-D12C69B2C3DB@easesoftware.com> From: Rob Sargent In-Reply-To: <8D4B16FB-BE56-446E-BDE5-D12C69B2C3DB@easesoftware.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------DUmTSo5DA082MlRHWvZ68m88 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 8/15/22 14:37, Perry Smith wrote: > > >> On Aug 15, 2022, at 08:55, David G. Johnston >> wrote: >> >> On Monday, August 15, 2022, Perry Smith wrote: >> >> I’ve been toying with row_number() and then sort by row_number >> descending and pick off the first row as the total number. >> >> >> Use count as a window function. > > I see others are commenting after David’s update so: > > Thank you David. > > This seems to work for me: > > SELECT count(*) OVER (), id, basename, sha1 FROM dateien WHERE > (lower(ext) in ( 'pxd' ) and ftype = 'file') ORDER BY sha1; > > > This has, e.g. 73, in the first column for all of the rows. > Any comparative timing statistics on that?  Especially on more than 73 records returned, because with that few just grab them all and get size() or length of what ever collection mechanism you're playing with. --------------DUmTSo5DA082MlRHWvZ68m88 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 8/15/22 14:37, Perry Smith wrote:


On Aug 15, 2022, at 08:55, David G. Johnston <david.g.johnston@gmail.com> wrote:

On Monday, August 15, 2022, Perry Smith <pedz@easesoftware.com> wrote:
I’ve been toying with row_number() and then sort by row_number descending and pick off the first row as the total number. 

Use count as a window function.

I see others are commenting after David’s update so:

Thank you David.

This seems to work for me:

SELECT count(*) OVER (), id, basename, sha1 FROM dateien WHERE (lower(ext) in ( 'pxd' ) and ftype = 'file') ORDER BY sha1;

This has, e.g. 73, in the first column for all of the rows.

Any comparative timing statistics on that?  Especially on more than 73 records returned, because with that few just grab them all and get size() or length of what ever collection mechanism you're playing with.
--------------DUmTSo5DA082MlRHWvZ68m88--