I want to pass a table name as a parameter in a Postgres function. I tried this code:
CREATE OR REPLACE FUNCTION some_f(param character varying) RETURNS inte
The first doesn't actually "work" in the sense that you mean, it works only in so far as it does not generate an error.
Try SELECT * FROM quote_ident('table_that_does_not_exist');
, and you will see why your function returns 1: the select is returning a table with one column (named quote_ident
) with one row (the variable $1
or in this particular case table_that_does_not_exist
).
What you want to do will require dynamic SQL, which is actually the place that the quote_*
functions are meant to be used.