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

From leaf_yxj
Subject Re: Please help me to take a look of the erros in my functions. Thanks.
Date
Msg-id 1333466844759-5615529.post@n5.nabble.com
Whole thread Raw
In response to Re: Re: Please help me to take a look of the erros in my functions. Thanks.  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Re: Please help me to take a look of the erros in my functions. Thanks.  (Bartosz Dmytrak <bdmytrak@gmail.com>)
List pgsql-general
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.

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Re: Please help me to take a look of the erros in my functions. Thanks.
Next
From: "Welty, Richard"
Date:
Subject: Re: 9.1.3: launching streaming replication