Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling a stored procedure within a stored procedure
    primarykey
    data
    text
    <p>I am trying to call a function within a function using sql on postgres 9.3.</p> <p>This question is related to <a href="http://bit.ly/1hB2Hn3" rel="nofollow">another post by me</a>.</p> <p>I have written the below function. So far I have failed to incorporate any kind of save-output (COPY) statement, so I am trying to work around this by creating a nested function print-out function. </p> <pre><code>CREATE FUNCTION retrieve_info(TEXT, TEXT) RETURNS SETOF retrieve_info_tbl AS $$ SELECT tblA.id, tblA.method, tblA.species, tblA.location FROM tblA WHERE method=$1 AND species=$2 GROUP BY id, method, species ORDER BY location $$ LANGUAGE 'sql'; </code></pre> <p>The above function works.</p> <p>An attempt to create a nested function.</p> <pre><code>CREATE FUNCTION print_out(TEXT, TEXT) RETURNS void AS $$ COPY (SELECT * FROM retrieve_info($1, $2)) TO 'myfilepath/test.csv' WITH CSV HEADER; $$ LANGUAGE 'sql'; </code></pre> <p>Calling nested function.</p> <pre><code>SELECT * FROM print_out('mtd1','sp1'); </code></pre> <p><strong>OUTPUT</strong></p> <p>The above gives this <code>ERROR: column "$1" does not exist SQL state: 42P02 Context: SQL function "print_out" statement 1</code>. However, when substituting the arg1, arg2 in print_out() with 'mtd1','sp1' the correct output is printed to test.csv (as seen below)</p> <pre><code>id | method | ind | location ---------------------------- 1a | mtd1 | sp3 | locA 1d | mtd1 | sp3 | locB </code></pre> <p>How would I get the arg1, arg2 of retrieve_info() to call arg1, arg2 properly within print_out()?</p> <p>I am completely stuck. Would appreciate any pointers, thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload