Re: Re: Please help me to take a look of the erros in my functions. Thanks. - Mailing list pgsql-general

From Bartosz Dmytrak
Subject Re: Re: Please help me to take a look of the erros in my functions. Thanks.
Date
Msg-id CAD8_UcZdKY_Xze43rktrDbiM3gbZNHJvoBQsXwo1Q9ps-FHohg@mail.gmail.com
Whole thread Raw
In response to Re: Please help me to take a look of the erros in my functions. Thanks.  (leaf_yxj <leaf_yxj@163.com>)
Responses Re: Please help me to take a look of the erros in my functions. Thanks.  (leaf_yxj <leaf_yxj@163.com>)
Re: Please help me to take a look of the erros in my functions. Thanks.  (leaf_yxj <leaf_yxj@163.com>)
List pgsql-general
One more thing:
TRUNCATE has option CASCASE:

I don't remember since when, but 9.X has this option.

Another thing: Do You really need this function.....
AFAIK since 8.4 postgres has TRUNCATE privilage on Table 
this is not the same as DELETE so, I think it is enough to grant this privilage to user

Regards,
Bartek


2012/4/3 leaf_yxj <leaf_yxj@163.com>
Tom,

Thanks.  I found out the key issue it. It's because the truncate command
can't have the "cascade".

For the other people reference. The right funcitons are :

***********************************************************

CREATE OR REPLACE FUNCTION truncate_t (IN tablename text)
RETURNS VOID
AS
$$
BEGIN
       EXECUTE 'TRUNCATE TABLE ' || quote_ident(tablename) || ';';
EXCEPTION
       WHEN undefined_table THEN
               RAISE EXCEPTION 'Table "%" does not exists', tablename;
END;
$$
LANGUAGE plpgsql SECURITY DEFINER STRICT;

***********************************************************

***********************************************************

CREATE OR REPLACE FUNCTION truncate_t (tablename text)
RETURNS VOID
AS
$$
BEGIN
       EXECUTE 'TRUNCATE TABLE ' || quote_ident(tablename) || ';';
EXCEPTION
       WHEN undefined_table THEN
               RAISE EXCEPTION 'Table "%" does not exists', tablename;
END;
$$
LANGUAGE plpgsql SECURITY DEFINER STRICT;

***********************************************************


usage : select truncate_t ('aaa');


Thanks everybody's help.

Regards.

Grace

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Please-help-me-to-take-a-look-of-the-erros-in-my-functions-Thanks-tp5613507p5615529.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

pgsql-general by date:

Previous
From: Bartosz Dmytrak
Date:
Subject: Re: Re: Please help me to take a look of the erros in my functions. Thanks.
Next
From: Merlin Moncure
Date:
Subject: Re: views, queries, and locks