pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PostgreSQL equivalent to Oracles ANYDATASET
5+ messages / 3 participants
[nested] [flat]

* PostgreSQL equivalent to Oracles ANYDATASET
@ 2020-11-13 16:56  Dirk Mika <Dirk.Mika@mikatiming.de>
  0 siblings, 2 replies; 5+ messages in thread

From: Dirk Mika @ 2020-11-13 16:56 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hello,

we’re currently using Oracle and have a few functions in some packages, which are defined e.g. as follows:


   FUNCTION get_results(p_id_series series.id_series%TYPE)

      RETURN ANYDATASET

      PIPELINED USING t_series_get_results;

It can be called like:

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?

BR
Dirk
--
Dirk Mika
Software Developer



[cid:mt_c1c59b3d-dd43-4ca6-992b-79f5a19f5999.png]

mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany



fon +49 2202 2401-1197
dirk.mika@mikatiming.de
www.mikatiming.de



AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika


[cid:sig_ineos_2940640b-c572-4bba-865f-9f3ba3fea686.png]<https://www.facebook.com/mikatiming;





Attachments:

mt_c1c59b3d-dd43-4ca6-992b-79f5a19f5999.png (image/png, 14.2K) download view image
sig_ineos_2940640b-c572-4bba-865f-9f3ba3fea686.png (image/png, 162.8K) download view image
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: PostgreSQL equivalent to Oracles ANYDATASET
@ 2020-11-13 17:04  Pavel Stehule <pavel.stehule@gmail.com>
  parent: Dirk Mika <Dirk.Mika@mikatiming.de>
  1 sibling, 1 reply; 5+ messages in thread

From: Pavel Stehule @ 2020-11-13 17:04 UTC (permalink / raw)
  To: Dirk Mika <Dirk.Mika@mikatiming.de>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi

pá 13. 11. 2020 v 17:57 odesílatel Dirk Mika <Dirk.Mika@mikatiming.de>
napsal:

> Hello,
>
>
>
> we’re currently using Oracle and have a few functions in some packages,
> which are defined e.g. as follows:
>
>
>
>    FUNCTION get_results(p_id_series series.id_series%TYPE)
>
>       RETURN ANYDATASET
>
>       PIPELINED USING t_series_get_results;
>
>
>
> It can be called like:
>
>
>
> 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?
>

Currently there is not this possibility

Theoretically you can use a function, that returns refcursor, and outside
function you can read this cursor

http://okbob.blogspot.com/2008/08/using-cursors-for-generating-cross.html

Regards

Pavel

>
>
> BR
>
> Dirk
> --
> Dirk Mika
>
>
> *Software Developer *
>
>
>
> mika:timing GmbH
> Strundepark - Kürtener Str. 11b
> 51465 Bergisch Gladbach
> Germany
>
> fon +49 2202 2401-1197
> dirk.mika@mikatiming.de
> www.mikatiming.de
>
> AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
> Geschäftsführer: Harald Mika, Jörg Mika
>
> <https://www.facebook.com/mikatiming;
>
>
>
>

Attachments:

mt_c1c59b3d-dd43-4ca6-992b-79f5a19f5999.png (image/png, 14.2K) download view image
sig_ineos_2940640b-c572-4bba-865f-9f3ba3fea686.png (image/png, 162.8K) download view image
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: PostgreSQL equivalent to Oracles ANYDATASET
@ 2020-11-13 17:23  Christoph Moench-Tegeder <cmt@burggraben.net>
  parent: Dirk Mika <Dirk.Mika@mikatiming.de>
  1 sibling, 1 reply; 5+ messages in thread

From: Christoph Moench-Tegeder @ 2020-11-13 17:23 UTC (permalink / raw)
  To: Dirk Mika <Dirk.Mika@mikatiming.de>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

## 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





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: PostgreSQL equivalent to Oracles ANYDATASET
@ 2020-11-14 11:20  Dirk Mika <Dirk.Mika@mikatiming.de>
  parent: Christoph Moench-Tegeder <cmt@burggraben.net>
  0 siblings, 0 replies; 5+ messages in thread

From: Dirk Mika @ 2020-11-14 11:20 UTC (permalink / raw)
  To: Christoph Moench-Tegeder <cmt@burggraben.net>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi,

many thanks for this suggestion. But the problem with this is that you have to know which columns are returned when you call the function.

Regards
Dirk

--
Dirk Mika
Software Developer



[cid:mt_c1c59b3d-dd43-4ca6-992b-79f5a19f5999.png]

mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany



fon +49 2202 2401-1197
dirk.mika@mikatiming.de
www.mikatiming.de



AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika
Von: Christoph Moench-Tegeder <cmt@burggraben.net>
Datum: Freitag, 13. November 2020 um 18:23
An: Dirk Mika <Dirk.Mika@mikatiming.de>
Cc: "pgsql-general@lists.postgresql.org" <pgsql-general@lists.postgresql.org>
Betreff: Re: PostgreSQL equivalent to Oracles ANYDATASET

## Dirk Mika (Dirk.Mika@mikatiming.de<mailto: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



Attachments:

mt_c1c59b3d-dd43-4ca6-992b-79f5a19f5999.png (image/png, 14.2K) download view image
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: PostgreSQL equivalent to Oracles ANYDATASET
@ 2020-11-14 14:22  Dirk Mika <Dirk.Mika@mikatiming.de>
  parent: Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Dirk Mika @ 2020-11-14 14:22 UTC (permalink / raw)
  To: Pavel Stehule <pavel.stehule@gmail.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi,

That looks promising. I'll take a closer look at that.

Regards
Dirk

--
Dirk Mika
Software Developer



[cid:mt_c1c59b3d-dd43-4ca6-992b-79f5a19f5999.png]

mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany



fon +49 2202 2401-1197
dirk.mika@mikatiming.de
www.mikatiming.de



AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika
Von: Pavel Stehule <pavel.stehule@gmail.com>
Datum: Freitag, 13. November 2020 um 18:05
An: Dirk Mika <Dirk.Mika@mikatiming.de>
Cc: "pgsql-general@lists.postgresql.org" <pgsql-general@lists.postgresql.org>
Betreff: Re: PostgreSQL equivalent to Oracles ANYDATASET

Hi

pá 13. 11. 2020 v 17:57 odesílatel Dirk Mika <Dirk.Mika@mikatiming.de<mailto:Dirk.Mika@mikatiming.de>> napsal:
Hello,

we’re currently using Oracle and have a few functions in some packages, which are defined e.g. as follows:


   FUNCTION get_results(p_id_series series.id_series%TYPE)

      RETURN ANYDATASET

      PIPELINED USING t_series_get_results;

It can be called like:

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?

Currently there is not this possibility

Theoretically you can use a function, that returns refcursor, and outside function you can read this cursor

http://okbob.blogspot.com/2008/08/using-cursors-for-generating-cross.html

Regards

Pavel

BR
Dirk
--
Dirk Mika
Software Developer


[cid:175c28eef6b1377a7f41]

mika:timing GmbH
Strundepark - Kürtener Str. 11b
51465 Bergisch Gladbach
Germany


fon +49 2202 2401-1197
dirk.mika@mikatiming.de<mailto:dirk.mika@mikatiming.de>
www.mikatiming.de<http://www.mikatiming.de;

AG Köln HRB 47509 * WEEE-Reg.-Nr. DE 90029884
Geschäftsführer: Harald Mika, Jörg Mika




[cid:175c28eef6d822336482]<https://www.facebook.com/mikatiming;





Attachments:

image001.png (image/png, 14.2K) download view image
image002.png (image/png, 162.8K) download view image
mt_c1c59b3d-dd43-4ca6-992b-79f5a19f5999.png (image/png, 14.2K) download view image
^ permalink raw reply [nested|flat] 5+ messages in thread


end of thread, other threads:[~2020-11-14 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-11-13 16:56 PostgreSQL equivalent to Oracles ANYDATASET Dirk Mika <Dirk.Mika@mikatiming.de>
2020-11-13 17:04 ` Pavel Stehule <pavel.stehule@gmail.com>
2020-11-14 14:22   ` Dirk Mika <Dirk.Mika@mikatiming.de>
2020-11-13 17:23 ` Christoph Moench-Tegeder <cmt@burggraben.net>
2020-11-14 11:20   ` Dirk Mika <Dirk.Mika@mikatiming.de>

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