Re: Appetite for syntactic sugar to match result set columns to UDT fields?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Philip Warner <pjw(at)rhyme(dot)com(dot)au>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Appetite for syntactic sugar to match result set columns to UDT fields?
Date: 2025-09-05 14:08:10
Message-ID: 1364243.1757081290@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Philip Warner <pjw(at)rhyme(dot)com(dot)au> writes:
> I'd like a formulation like:
> Select Row(T1.T1F7 as F1, T2.T2F3 as F2, Tp.Fq as Fn)::FOO By Name
> Or
> Select FOO(F1:=T1.T1F7, F2:=T2.T2F3, Fn:=Tp.Fq)

> Basically: it's some form of UDT constructor with named parameters,
> whether by cast, pseudo function call or some other mechanism.

Well, you can build a real function call that does that:

CREATE FUNCTION FOO(F1 int, F2 int, ...) RETURNS FOO AS ...;

SELECT FOO(F1 => T1.T1F7, F2 => T2.T2F3, ...) FROM ...;

Admittedly you have to get the ROW() constructor right in the
body of function FOO, but then you've got it. This approach
also lets you insert appropriate default values for unspecified
columns, which is a feature we surely wouldn't build in if this
were wired-in syntax.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Pierrick 2025-09-05 14:22:14 Only one version can be installed when using extension_control_path
Previous Message David Geier 2025-09-05 14:03:02 Re: Use merge-based matching for MCVs in eqjoinsel