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 1kdcnT-00053T-Ef for pgsql-general@arkaria.postgresql.org; Fri, 13 Nov 2020 17:23:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kdcmw-0004mm-QH for pgsql-general@arkaria.postgresql.org; Fri, 13 Nov 2020 17:23:06 +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 1kdcmw-0004me-IU for pgsql-general@lists.postgresql.org; Fri, 13 Nov 2020 17:23:06 +0000 Received: from smtp.burggraben.net ([2a01:4f8:140:510a::3]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kdcmu-0006v0-DN for pgsql-general@lists.postgresql.org; Fri, 13 Nov 2020 17:23:05 +0000 Received: from elch.exwg.net (elch.exwg.net [IPv6:2001:470:7120:1:127b:44ff:fe4f:148d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "elch.exwg.net", Issuer "Christoph Moench-Tegeder" (verified OK)) by smtp.burggraben.net (Postfix) with ESMTPS id 201D8C00311; Fri, 13 Nov 2020 18:23:02 +0100 (CET) Received: by elch.exwg.net (Postfix, from userid 1000) id BF84613982F; Fri, 13 Nov 2020 18:23:01 +0100 (CET) Date: Fri, 13 Nov 2020 18:23:01 +0100 From: Christoph Moench-Tegeder To: Dirk Mika Cc: "pgsql-general@lists.postgresql.org" Subject: Re: PostgreSQL equivalent to Oracles ANYDATASET Message-ID: References: <198CEF8B-3DD8-4396-A6AF-E0D2E3567FBB@mikatiming.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <198CEF8B-3DD8-4396-A6AF-E0D2E3567FBB@mikatiming.de> User-Agent: Mutt/2.0.0 (2020-11-07) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ## Dirk Mika (Dirk.Mika@mikatiming.de): > SELECT * FROM TABLE(series_pkg.get_results(1)); > > The purpose of this function is to provide a DATASET, which has > different columns in the result depending on the passed parameter. > > Is there any way to achieve something similar in PostreSQL? testing=# CREATE OR REPLACE FUNCTION public.rr(p INTEGER) RETURNS SETOF RECORD LANGUAGE plpgsql AS $function$ BEGIN IF p = 1 THEN RETURN NEXT ('k1'::TEXT, 'v1'::TEXT); RETURN NEXT ('k2'::TEXT, 'v2'::TEXT); ELSE RETURN NEXT (23::INTEGER, 42::INTEGER, 'abc'::TEXT); RETURN NEXT (42::INTEGER, 23::INTEGER, 'xyz'::TEXT); END IF; RETURN; END; $function$; CREATE FUNCTION testing=# SELECT * FROM rr(2) f(a INTEGER, b INTEGER, c TEXT); a | b | c ----+----+----- 23 | 42 | abc 42 | 23 | xyz (2 rows) testing=# SELECT * FROM rr(1) f(x TEXT, y TEXT); x | y ----+---- k1 | v1 k2 | v2 (2 rows) Regards, Christoph -- Spare Space