Thread: GRANT SELECT ON table TO $1
Hi all,
CREATE OR REPLACE FUNCTION func(TEXT)
RETURNS integer
AS $$
BEGIN
GRANT SELECT ON table1 TO $1;
END;
$$
LANGUAGE 'plpgsql';
and I get something like this:
ERROR: error de sintaxis en o cerca de «$1» at character 31
QUERY: GRANT SELECT ON table1 TO $1
CONTEXT: SQL statement in PL/PgSQL function "func" near line 7
LINEA 1: GRANT SELECT ON table1 TO $1
I think that the problem is the data type (TEXT) but I can't find the solution.
Can somebody help me with that problem please.
Thanks.
Sorry for my English.
"David Barajas" <david@sonrie.net> writes: > CREATE OR REPLACE FUNCTION func(TEXT) > RETURNS integer > AS $$ > BEGIN > GRANT SELECT ON table1 TO $1; Can't do that: a $-parameter is a placeholder for a data value, not a name, and GRANT wants a name. You could do EXECUTE 'GRANT SELECT ON table1 TO ' || quote_ident($1); regards, tom lane