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 1tDQaU-000d3r-2e for pgsql-general@arkaria.postgresql.org; Tue, 19 Nov 2024 15:56:22 +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 1tDQaS-00ECF1-Ei for pgsql-general@arkaria.postgresql.org; Tue, 19 Nov 2024 15:56:20 +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 1tDQaS-00ECEs-3O for pgsql-general@lists.postgresql.org; Tue, 19 Nov 2024 15:56:20 +0000 Received: from mail-oa1-x34.google.com ([2001:4860:4864:20::34]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tDQaP-002m2f-Kw for pgsql-general@postgresql.org; Tue, 19 Nov 2024 15:56:19 +0000 Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-29692ad4b42so703506fac.3 for ; Tue, 19 Nov 2024 07:56:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732031776; x=1732636576; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=HwY8ioD/EAfZNunW2APizwqGpK1pOfCN+rYS0d8pQ8I=; b=UmnlJaoKnwD7+RoruPU79I75tE2nHV6JhdAYYIIs3WmLvPtCOlog9mL8xdP6YKx0/a op+w8P3Is0L2vEKB7Mdd0eQzS0dC4FtwaynrX6VXxXmjXtbHFw0PIk9CG2+f0BEi9Io0 vgq2Q/3JuPWni3N/IBjUv0k370n8h+spY60VeOe+BCcTfvRULkdjkxVOUzbxyyA2G6sY bMbjBEQkfew9SG6+BB7HfrZkVtNo8V1WGLXOoteLREb7wseY/vWN5S0O+o2zfvXueydS IzEgMPjgKiwTMpwll9WEY+S1Z5jzrH91o2hpDxqN2qfzH99ExKSxqA4H3Uv6s9qCiYKK Cb8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732031776; x=1732636576; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HwY8ioD/EAfZNunW2APizwqGpK1pOfCN+rYS0d8pQ8I=; b=r7Ctk2o3oxWAOdl5xd7cLRcxW38BbrU5hFvRJLXYp2UF1lGV5a9r3wequ6YDAJbQNt mrVB+5COqiINEeiiqf5voBl7Z3YssrFsMmTDn5xGBh+di2Pmh+MGBV3aiz/Z4W3DEcgn BuGt969+GAjRIRjs/B5d+P4u6xY4LxLSnsBznbuR/wCOvHDpthc3PkVhZKSZOiQb/Fnc niBanXGPGe11FRs6PiWWuZ0HNCEVygX0tBUi2I2bQ4Pki5sswc2Ls8VuFwre0LHnAe4+ ITvadpHcEfC/lUxAwwg1UKn1bmYcu6v+G13LUOqC0impwwRV9x/ktr4od/rTXyYogKZh nZsg== X-Gm-Message-State: AOJu0Ywmz1lXN28/J9UQoGM1WHPRImT4NAaP+9fy8/HLi1Oqb/QZ8sYt qPqbHEINtxUiUkThNfRQDq0XRUko3LQLsGjOBiAgwCc70y+EFUfDJfJpImQEQDnhFAUVEOh+DEO D8ZpLDCnueW+1b86KUZekoOuJTsE= X-Google-Smtp-Source: AGHT+IFODnuOlLuGpFyGJbdfS93jrpYEwn6RfiihZjQEpLlUImsAAn5ZShcXTj8GWpMj/ELMTGYTL4leolWHUa6CwLU= X-Received: by 2002:a05:6870:7d88:b0:27c:52a1:f311 with SMTP id 586e51a60fabf-2962e0f343cmr13359743fac.42.1732031775709; Tue, 19 Nov 2024 07:56:15 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "David G. Johnston" Date: Tue, 19 Nov 2024 08:55:39 -0700 Message-ID: Subject: Re: Specifying columns returned by a function, when the function is in a SELECT column list? To: Ron Johnson Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000bb1f9106274612c3" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000bb1f9106274612c3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Nov 19, 2024 at 8:48=E2=80=AFAM Ron Johnson wrote: > It's trivial to specify columns when a table-returning function is the > FROM clause, but how does one specify columns when the table-returning > function is a column in a SELECT clause? > You don't/cannot. And with lateral you shouldn't find the need to hack around it either. Non-scalar function calls in the select clause are now obsolete. In the select clause the function call returns a single-column of composite type with the names of the fields in the composite already known. As the query scope where you invoke the function you should only use the composite. If you need to dive into its fields you'd need a subquery - ideally one that doesn't risk being optimized away due to a multiple-evaluation hazard. David J. --000000000000bb1f9106274612c3 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Nov 19, 2024 at 8:48=E2=80=AFAM Ron Johnson <ronljohnsonjr@gmail.com> wr= ote:
It's trivial to specify = columns when a table-returning function is the FROM clause, but how does on= e specify columns when the table-returning function is a column in a SELECT= clause?

You don't/canno= t.=C2=A0 And with lateral you shouldn't find the need to hack around=C2= =A0it either.=C2=A0 Non-scalar function=C2=A0calls in the select clause are= now obsolete.

In the select clause the functi= on call returns a single-column of composite type with the names of the fie= lds in the composite already known.=C2=A0 As the query scope where you invo= ke the function you should only use the composite.=C2=A0 If you need to div= e into its fields you'd need a subquery - ideally one that doesn't = risk being optimized away due to a multiple-evaluation hazard.

=
David J.
--000000000000bb1f9106274612c3--