title: PostgreSQL: How to differentiate stored procedures and table-valued functions?
body: <p>Question:</p>
  
  <p>In Microsoft SQL Server, there are stored procedures, and there are table-valued functions.</p>
  
  <p>The difference is, from a stored procedure, I cannot do further selects, while from a table-valued function, I can.</p>
  
  <p>e.g.</p>
  
  <p><code>SELECT * FROM sp_whatever WHERE xxx</code> is illegal<br />
  while<br />
  <code>SELECT * FROM TVF_whatever WHERE xxx</code> is perfectly legal<br /></p>
  
  <p>Now my question:</p>
  
  <p>In PostgreSQL, when I look at <code>information_schema.routines</code>, how can I differentiate table valued functions, and procedures ? </p>
  
  <p>Is there a difference at all ?</p>
  
  <p>And in general, how can I differentiate functions and procedures in PostgreSQL?</p>
  
  <p>I mean theoretically, on SQL-server, one can differentiate them like this:<br />
  Table valued function: <code>information_schema.data_type = 'table'</code><br />
  stored procedures: <code>information_schema.data_type IS NULL</code><br />
  functions: <code>information_schema.data_type != 'table' AND information_schema.data_type IS NOT NULL</code><br /></p>
  
  <p>How is this done in Postgres? </p>
  
  <p>Theoretically, a stored procedure has return type void, but since a stored procedure can also return a table, there is no way to differentiate between tvf and stored precedure - assuming there <em>is</em> a difference.</p>
  
  <p>So my question could also be formulated:<br />
  In PostGreSQL, how do I create a table-valued function, and how do I create a stored procedure (1 example each). <br />
  <br />
  I'm interested in the difference in the return type between the two, if there is any.<br />
  <br /></p>