create one function to let other user execute vacuum command. got such an error.

Started by leaf_yxjabout 14 years ago3 messagesgeneral
Jump to latest
#1leaf_yxj
leaf_yxj@163.com

create one function to let other user execute vacuum command. got such an
error. Please help. Thanks. Regards . Grace

rrp=> create function vacuum_f ( tablename char(100))
Returns char(100) AS $$
vacuum tablename;
$$ Language plpgsql security definer;
ERROR: syntax error at or near "vacuum"
LINE 3: vacuum tablename;
^
rrp=>

--
View this message in context: http://postgresql.1045698.n5.nabble.com/create-one-function-to-let-other-user-execute-vacuum-command-got-such-an-error-tp5599318p5599318.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

#2Guillaume Lelarge
guillaume@lelarge.info
In reply to: leaf_yxj (#1)
Re: create one function to let other user execute vacuum command. got such an error.

On Tue, 2012-03-27 at 18:51 -0700, leaf_yxj wrote:

create one function to let other user execute vacuum command. got such an
error. Please help. Thanks. Regards . Grace

rrp=> create function vacuum_f ( tablename char(100))
Returns char(100) AS $$
vacuum tablename;
$$ Language plpgsql security definer;
ERROR: syntax error at or near "vacuum"
LINE 3: vacuum tablename;
^
rrp=>

Well, first, it doesn't follow PL/pgsql guidelines. You need at least a
BEGIN at the beginning of the function, and an END at the end.

But even with this, you cannot use VACUUM in a function. Don't remember
the reason why right now, but all you'll get is this error:

ERROR: VACUUM cannot be executed from a function or multi-command
string

--
Guillaume
http://blog.guillaume.lelarge.info
http://www.dalibo.com

#3Grzegorz Jaśkiewicz
gryzman@gmail.com
In reply to: Guillaume Lelarge (#2)
Re: create one function to let other user execute vacuum command. got such an error.

On 28 Mar 2012, at 07:44, Guillaume Lelarge wrote:

On Tue, 2012-03-27 at 18:51 -0700, leaf_yxj wrote:

create one function to let other user execute vacuum command. got such an
error. Please help. Thanks. Regards . Grace

rrp=> create function vacuum_f ( tablename char(100))
Returns char(100) AS $$
vacuum tablename;
$$ Language plpgsql security definer;
ERROR: syntax error at or near "vacuum"
LINE 3: vacuum tablename;
^
rrp=>

Well, first, it doesn't follow PL/pgsql guidelines. You need at least a
BEGIN at the beginning of the function, and an END at the end.

But even with this, you cannot use VACUUM in a function. Don't remember
the reason why right now, but all you'll get is this error:

ERROR: VACUUM cannot be executed from a function or multi-command
string

Because its not a transaction safe operation.
Beside's , what's with the char(100) ? Function like that,you should use text type.