From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Paul Förster <paul.foerster@gmail.com>
To: Post Gresql <postgresql@taljaren.se>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: create type with %type or %rowtype
Date: Thu, 19 Nov 2020 06:46:19 -0800
Message-ID: <4eaaea2a-5dd4-a865-6d27-d4988d739ccf@aklaver.com> (raw)
In-Reply-To: <5EABB320-084A-42CD-8610-5BF6A37DE811@gmail.com>
References: <4fb49f43-6753-b692-9ca7-61052f63a929@taljaren.se>
<CAKFQuwYSNf4g0_QHwbMnX6LAcmaQJJKG_Qd0yBkSutPQYafMqQ@mail.gmail.com>
<82b59d98-bc35-7212-b950-45ff585f3b12@taljaren.se>
<75e98bba-afa1-5c7a-f6a1-434fac52e4a0@aklaver.com>
<bd2b55d4-3509-d055-02f3-77c2d88a3eb1@taljaren.se>
<5EABB320-084A-42CD-8610-5BF6A37DE811@gmail.com>
On 11/18/20 10:04 PM, Paul Förster wrote:
> Hi,
>
>> On 18. Nov, 2020, at 22:08, Post Gresql <postgresql@taljaren.se> wrote:
>>
>> I might be stupid, but where in the document for create function does it say that the return type can be a table?
>>
>> From the doc for version 13 https://www.postgresql.org/docs/13/sql-createfunction.html
>>
>> "rettype
>> The return data type (optionally schema-qualified). The return type can be a base, composite, or domain type, or can reference the type of a table column."
>
> right in the syntax:
>
> CREATE [ OR REPLACE ] FUNCTION
> name ( [ [ argmode ] [ argname ] argtype [ { DEFAULT | = } default_expr
> ] [, ...] ] )
> [ RETURNS rettype
> | RETURNS TABLE ( column_name column_type [, ...] ) ]
>
> "RETURNS TABLE(...)" is probably what you're looking for?
That is a variation on the theme. The OP was looking for declaring a
table%ROWTYPE in RETURNS rettype. You can do that by using the table
composite type. Since RETURNS TABLE is essentially an alias for RETURNS
SETOF you can use it to return a set of the table composite type. Though
in RETURNS TABLE you can also 'create' your own table that has nothing
to do with an existing table composite type.
>
> Cheers,
> Paul
>
--
Adrian Klaver
adrian.klaver@aklaver.com
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adrian.klaver@aklaver.com, paul.foerster@gmail.com, postgresql@taljaren.se
Subject: Re: create type with %type or %rowtype
In-Reply-To: <4eaaea2a-5dd4-a865-6d27-d4988d739ccf@aklaver.com>
References: <4fb49f43-6753-b692-9ca7-61052f63a929@taljaren.se> <CAKFQuwYSNf4g0_QHwbMnX6LAcmaQJJKG_Qd0yBkSutPQYafMqQ@mail.gmail.com> <82b59d98-bc35-7212-b950-45ff585f3b12@taljaren.se> <75e98bba-afa1-5c7a-f6a1-434fac52e4a0@aklaver.com> <bd2b55d4-3509-d055-02f3-77c2d88a3eb1@taljaren.se> <5EABB320-084A-42CD-8610-5BF6A37DE811@gmail.com> <4eaaea2a-5dd4-a865-6d27-d4988d739ccf@aklaver.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox