0

I have a seemingly simple question, but can't find an answer for it. So far, I've been working with MSSQL, but recently a new project came up which uses PostgreSQL for all DB related stuff, and I don't have as much experience with postgre as I'd like to have. The thing is I need to write a simple function which returns, let's say N different datasets. In MSSQL this simply would look like

-- Stored procedure creation statements
SELECT * FROM dbo.Table1

SELECT * FROM dbo.Table2

...
-- End stored procedure 

Keep in mind, that all tables are different in structure (column count, names and etc.) So far, all I've found that could help me, is SETOF, but it seems that by using it, I can only return results of same rowtype.

Any kind of help would be appreciated.

brainpow3r
  • 13
  • 4
  • It would be best if you could give us an example of what you're tying to achieve. It would be also quite helpful if you also provide some data sample (with create table statements) and the exact expected result. – Jim Jones Jan 23 '20 at 12:49
  • Super strange question. If you want to use a stored procedure (the same as in MYSQL), just use it. [PostgreSQL Stored Procedure](https://www.postgresqltutorial.com/postgresql-create-procedure/) – PWND Jan 23 '20 at 12:51
  • 2
    It is somewhat possible, using a function declared as `returns setof refcuros` but working with that is really annoying. It is far less common to put queries into procedures or function in Postgres, let alone returning multiple different results from them. I have been working with relational databases for over 30 years now and (mainly Oracle and Postgres) I never had the need to return results from a procedure and most definitely not multiple results. –  Jan 23 '20 at 12:51

0 Answers0