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 1kflCh-00019G-IQ for pgsql-general@arkaria.postgresql.org; Thu, 19 Nov 2020 14:46:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kflCg-0008MR-GV for pgsql-general@arkaria.postgresql.org; Thu, 19 Nov 2020 14:46:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kflCf-0008MJ-49 for pgsql-general@lists.postgresql.org; Thu, 19 Nov 2020 14:46:30 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kflCa-0001og-NJ for pgsql-general@lists.postgresql.org; Thu, 19 Nov 2020 14:46:28 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 741F0B3D; Thu, 19 Nov 2020 09:46:21 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Thu, 19 Nov 2020 09:46:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=n L9X8Hr3Z/HqxNcuw5cNl8N0KxFZYjyDU4n7IgR8EfQ=; b=LHShRfVZZ9Bxq/2Mj cX3iSlXzw1sOhWOnBciXoBHJpsJjg2gSqxb1+GfjimcVIaBi9sWaTCSG/vzILjOT 90Zz7FyapzOI4sEan8B8+/xvnx8WEwQnqB0IL5C5IYAuBxpMIE414MP6ISg4ZQFT 0i7Enboqd/9XKgNmM8GpnQkrp2/4jwbW2bXWNgJvdOrnnxhKLxe/QEnyQZXRSKWS r2XjHYSHnT01GcpV1M9k83bdI3dYqDC4Ygvxh01qaOZ1n+qCKEDHB8guaNvxSxs3 YJ51SCGHs7gtCzvcqmqu7qHXe2NgsD4hCjCpdIVhkA8VdugIJnc+MPg8OfA3mpeP oDM5Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=nL9X8Hr3Z/HqxNcuw5cNl8N0KxFZYjyDU4n7IgR8E fQ=; b=NCp3qwK3/kwGFSLmLoHJ3CXzqoHLhHzx6hXmSbs/H/FInLpaY0DkH5wf0 BBCtFIs6+MYTjw0+H2Ouzj9sTkP6Y8rIQU7jLl1T1JtJJKS3eDEI/ZLNwX3tEmzm awIKDrrgy7ZnvwYKaPe5f3jJ8jjbxrVUcuxnbHBjXiYbEMqULvwDsbfW1gye++tT VlbMp+fpNxNeve2iSxh/+8e8cCYodBYUgE6Eq7OK7c+TQnLixG6O8YeFjtIlS3Xo 4B8CZ2sw6rxizHJdEfcswY/HdVwWFovkgF0gQ9ZjmlOK0GQ1F3L69SkjkPVxuxOs gp+n/5pyTe8Zrp/1ozyyDWHuxA+pQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudefjedgieekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeduudefjeetveffhefgudehtdfhvdetkeeiueehfeev veduteekleeuheegudehhfenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cukfhppeejhedrudejvddrudelrddufeelnecuvehluhhsthgvrhfuihiivgeptdenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomh X-ME-Proxy: Received: from [192.168.1.4] (75-172-19-139.tukw.qwest.net [75.172.19.139]) by mail.messagingengine.com (Postfix) with ESMTPA id 086513280069; Thu, 19 Nov 2020 09:46:19 -0500 (EST) Subject: Re: create type with %type or %rowtype To: =?UTF-8?Q?Paul_F=c3=b6rster?= , Post Gresql Cc: pgsql-general@lists.postgresql.org References: <4fb49f43-6753-b692-9ca7-61052f63a929@taljaren.se> <82b59d98-bc35-7212-b950-45ff585f3b12@taljaren.se> <75e98bba-afa1-5c7a-f6a1-434fac52e4a0@aklaver.com> <5EABB320-084A-42CD-8610-5BF6A37DE811@gmail.com> From: Adrian Klaver Message-ID: <4eaaea2a-5dd4-a865-6d27-d4988d739ccf@aklaver.com> Date: Thu, 19 Nov 2020 06:46:19 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 MIME-Version: 1.0 In-Reply-To: <5EABB320-084A-42CD-8610-5BF6A37DE811@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/18/20 10:04 PM, Paul Förster wrote: > Hi, > >> On 18. Nov, 2020, at 22:08, Post Gresql 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