agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
SETOF any table records AS return in pgSQL functions
2+ messages / 2 participants
[nested] [flat]

* SETOF any table records AS return in pgSQL functions
@ 2017-09-20 15:16 athinivas <athinivas@gmail.com>
  2017-09-20 16:20 ` Re: SETOF any table records AS return in pgSQL functions David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: athinivas @ 2017-09-20 15:16 UTC (permalink / raw)
  To: pgsql-sql

hi,

Could anyone say pgSQL equivalent of SELECT * FROM any_table inside stored
procedure in MySQL ??

PS: I'm able to understand only functions are there in pgSQL. But couldn't
get a way for SETOF polymorphic columns inside functions.

Thanks athi



--
Sent from: http://www.postgresql-archive.org/PostgreSQL-sql-f2142323.html


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



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

* Re: SETOF any table records AS return in pgSQL functions
  2017-09-20 15:16 SETOF any table records AS return in pgSQL functions athinivas <athinivas@gmail.com>
@ 2017-09-20 16:20 ` David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: David G. Johnston @ 2017-09-20 16:20 UTC (permalink / raw)
  To: athinivas <athinivas@gmail.com>; +Cc: pgsql-sql

On Wed, Sep 20, 2017 at 8:16 AM, athinivas <athinivas@gmail.com> wrote:

> hi,
>
> Could anyone say pgSQL equivalent of SELECT * FROM any_table inside stored
> procedure in MySQL ??
>
> PS: I'm able to understand only functions are there in pgSQL. But couldn't
> get a way for SETOF polymorphic columns inside functions.
>

​Went looking for a doc example but couldn't quickly find one...

In short you have two choices in PostgreSQL:
1. Define the return record structure in CREATE FUNCTION​
2. Define the return record structure in the FROM clause <FROM func_call
(col1 text, col2 int)>

To write a function that supports #2 you do:

CREATE FUNCTION ... RETURNS SETOF record

This is documented at least at:

https://www.postgresql.org/docs/9.6/static/sql-select.html

FROM Clause -> function_name (4th paragraph)

The syntax blob includes a "column_definition" placeholder though there is
no format definition on that page - only the "followed by a column
definition list in the form ( column_name data_type [, ... ])" fragment
buried within this section.

David J.

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


end of thread, other threads:[~2017-09-20 16:20 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-09-20 15:16 SETOF any table records AS return in pgSQL functions athinivas <athinivas@gmail.com>
2017-09-20 16:20 ` David G. Johnston <david.g.johnston@gmail.com>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox