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 1sp8Sw-00GtLn-1T for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2024 15:44:11 +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 1sp8Sv-005fqO-9N for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2024 15:44:09 +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 1sp8Su-005fm0-Q8 for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2024 15:44:08 +0000 Received: from mail-oa1-x2b.google.com ([2001:4860:4864:20::2b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sp8Sj-000zH0-3l for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2024 15:44:07 +0000 Received: by mail-oa1-x2b.google.com with SMTP id 586e51a60fabf-2781cb281abso1119412fac.1 for ; Fri, 13 Sep 2024 08:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726242236; x=1726847036; 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=mXhZnMyRTFA/kBktcVZa49OByCpBISOasV83DI6TUZM=; b=TlyYRdEOiMj9/UdSEX/HPzHaj++nqe0ECUbB69r2Be65SVSviTeC+Q/nfczcv/WCaw qzlxSY2kOIUlKLqFdNEP+ALB5hoHjMdCFT2ZxM3Kjelw75QkXtUvfxU4O0JIzSIGnzAq utTTJzt7bqvSy5Z/z0jetNgKasZZzEkV0pFkKrxlXv/gwpb/NGflER6mdBDyKZ6mZxhc QZBEj7bu+SSuUPZca1bwVx8v7R/f5QPifeYiq1d63Y8qy3LFa356TJXzmAK7nayfeGGD K2eX5mr5i1WlxsH/Oj0mcfFnYRMOBJrKzMlocei558HQ6W8pJc/+9cL4bI9c0Jcn0YXC zw7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726242236; x=1726847036; 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=mXhZnMyRTFA/kBktcVZa49OByCpBISOasV83DI6TUZM=; b=O0XGD0LA/949iL4HQXDJaybjaMos+CG7tSRIu3Bifq2mYg8iGeQMYkI2eR3/ynEMb7 Y5NzWs6ew4qGOUSsQyMhj0HH3WMX7NW0v2clA2rYJMNUR/gPK+7R2IYelTfBoojMsNWr b3gUMnbwy7wIN1rjuW/1ze6kJgLmKNsn0PTf92RJOVB5QBy6XDFiuJQ+XT7eg6648eRi qSKOvgiXCjUs9YwAJENR1Jm1nmzkYcEzj4sGYLkiKwpv8/aVFiHbdGgw7oIybQ/WMBE/ d3cGqkeLZ/BoV/eBfHMr+YL7I3ZNvG398sdAUmh/J3OG+dyrp66gODM0z07ma+NI5f8F fymQ== X-Forwarded-Encrypted: i=1; AJvYcCUAcOTSYhaQzMLcQ6mmbF4d3MajpnoFn3NtQEp/QMwxapkhiYTxaUVilnB52akU/M0EtSQkRvqnwigOBNFx@lists.postgresql.org X-Gm-Message-State: AOJu0YyJ00DRAVd4nDczqqjZdwnVQiHuE8zVbFMuPC5LWcZVuLdiT3vI 9AZJWJ72SYRiGCJKPk81nh3OvvAeb/yD3iezAq8ii9KhPAn29U/QviIopepq4W0k/AkZsweel6m ysqd8MJssXhsPMEgNuygsUzolQ2Y= X-Google-Smtp-Source: AGHT+IEwRjKcLKMHeHs7JhA195meku2/4aP64/Fq/ZmWWLM77ZyOiwAFevBDXVMpDsnkbs65QSUvgZlICWTq6qCGeKE= X-Received: by 2002:a05:6870:7027:b0:277:ef2f:3dc with SMTP id 586e51a60fabf-27c3f62ca07mr4346617fac.33.1726242236510; Fri, 13 Sep 2024 08:43:56 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a8a:e0e:0:b0:557:c384:fb61 with HTTP; Fri, 13 Sep 2024 08:43:54 -0700 (PDT) In-Reply-To: References: <88e52d11-6185-473d-9eb2-673b62cb2426@gmx.net> From: "David G. Johnston" Date: Fri, 13 Sep 2024 08:43:54 -0700 Message-ID: Subject: Re: Functionally dependent columns in SELECT DISTINCT To: Willow Chargin Cc: "shammat@gmx.net" , "pgsql-general@lists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000004dba54062202171e" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000004dba54062202171e Content-Type: text/plain; charset="UTF-8" On Friday, September 13, 2024, Willow Chargin wrote: > In reality I really do want the ID columns of the > *most recent* items. > Use a window function to rank them and pull out rank=1, or use a lateral subquery to surgically (fetch first 1) retrieve the first row when sorted by recency descending. David J. --0000000000004dba54062202171e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Friday, September 13, 2024, Willow Chargin <postgresql@wchargin.com> wrote:
In reality I really do want the ID columns of the
*most recent* items.

Use a window function to rank them and pul= l out rank=3D1, or use a lateral subquery to surgically (fetch first 1) ret= rieve the first row when sorted by recency descending.

=
David J.=C2=A0
--0000000000004dba54062202171e--