Using sql on postgres 9.3 (MacOSX), how would I reference the arguments from a nested function to the arguments of the top-level function? Below is a dummy example.
CREATE FUNCTION f1(x TEXT, y TEXT) RETURNS SETOF some_tbl AS $$
SELECT col1, col2, col3
FROM some_other_tbl
WHERE col1=x AND col2=y
GROUP BY col1;
$$ LANGUAGE 'sql';
CREATE FUNCTION f2(x TEXT, y TEXT) RETURNS void AS $$
COPY (SELECT * FROM f1(x, y) TO 'myfilepath/test.csv'
$$ LANGUAGE 'sql';
I have looked through the Arguments for SQL Functions and found that you can reference arguments using the syntax $n
. So I substituted (x, y) in the nested function with ($1, $2)
but when calling f2 it gives the error messages ERROR: there is no parameter $1
SQL state: 42P02
Context: SQL function "f2" statement 1