It is well known that you cannot perform a SELECT
from a stored procedure in either Oracle or SQL Server (and presumably most other mainstream RDBMS products).
Generally speaking, there are several obvious "issues" with selecting from a stored procedure, just two that come to mind:
a) The columns resulting from a stored procedure are indeterminate (not known until runtime)
b) Because of the indeterminate nature of stored procedures, there would be issues with building database statistics and formulating efficient query plans
As this functionality is frequently desired by users, a number of workaround hacks have been developed over time:
http://www.club-oracle.com/threads/select-from-stored-procedure-results.3147/
http://www.sommarskog.se/share_data.html
SQL Server in particular has the function OPENROWSET
that allows you to join to or select from almost anything: https://msdn.microsoft.com/en-us/library/ms190312.aspx
....however, DBA's tend to be very reluctant to enable this for security reasons.
So to my question: while there are some obvious issues or performance considerations involved in allowing joins to or selects from stored procedures, is there some fundamental underlying technical reason why this capability is not supported in RDBMS platforms?
EDIT:
A bit more clarification from the initial feedback....yes, you can return a resultset from a stored procedure, and yes, you can use a (table valued) function rather than a stored procedure if you want to join to (or select from) the resultset - however, this is not the same thing as JoiningTo / SelectingFrom a stored procedure. If you are working in a database that you have complete control over, then you have the option of using a TVF. However, it is extremely common that you find yourself working in a 3rd party database and you are forced to call pre-existing stored procedures; or, often times you would like to join to system stored procedures such as: sp_execute_external_script (https://msdn.microsoft.com/en-us/library/mt604368.aspx).
EDIT 2:
On the question of whether PostgreSQL can do this, the answer is also no: Can PostgreSQL perform a join between two SQL Server stored procedures?
where
clause. – Vedda