From: Christoph Moench-Tegeder <cmt@burggraben.net>
To: Dirk Mika <Dirk.Mika@mikatiming.de>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: PostgreSQL equivalent to Oracles ANYDATASET
Date: Fri, 13 Nov 2020 18:23:01 +0100
Message-ID: <X67A9V2P8HkC/AF8@elch.exwg.net> (raw)
In-Reply-To: <198CEF8B-3DD8-4396-A6AF-E0D2E3567FBB@mikatiming.de>
References: <198CEF8B-3DD8-4396-A6AF-E0D2E3567FBB@mikatiming.de>
## 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
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: cmt@burggraben.net, Dirk.Mika@mikatiming.de
Subject: Re: PostgreSQL equivalent to Oracles ANYDATASET
In-Reply-To: <X67A9V2P8HkC/AF8@elch.exwg.net>
References: <198CEF8B-3DD8-4396-A6AF-E0D2E3567FBB@mikatiming.de> <X67A9V2P8HkC/AF8@elch.exwg.net>
* 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