2012/4/3 Alban Hertroys
> On 2 Apr 2012, at 22:28, Bartosz Dmytrak wrote:
>
> > That is right, there is no sense to use cursors here...
>
> I think you're wrong there: The OP is querying a system table for tables
> of a certain name, which I expect can contain multiple rows for tables of
> the sa
On 2 Apr 2012, at 22:02, leaf_yxj wrote:
> CREATE OR REPLACE FUNCTION truncate_t(tablename IN VARCHAR) RETURNS void AS
> $$
> DECLARE
> stmt RECORD;
> statements CURSOR FOR SELECT tablename FROM pg_catalog.pg_tables;
> BEGIN
> IF stmt IN statements then
> EXECUTE 'TRUNCAT
On 2 Apr 2012, at 22:28, Bartosz Dmytrak wrote:
> That is right, there is no sense to use cursors here...
I think you're wrong there: The OP is querying a system table for tables of a
certain name, which I expect can contain multiple rows for tables of the same
name in different schema's.
Of c
That is right, there is no sense to use cursors here...
CREATE OR REPLACE FUNCTION truncate_t (IN tablename text)
RETURNS VOID
AS
$$
BEGIN
EXECUTE 'TRUNCATE TABLE ' || quote_ident(tablename) || 'CASCADE;';
EXCEPTION
WHEN undefined_table THEN
RAISE EXCEPTION 'Table "%" does not exists', tablename
Hello
" IF stmt IN statements then " is nonsense.
use trapping exceptions instead
BEGIN
EXECUTE 'TRUNCATE TABLE ' || quote_ident(_tablename) || ' CASCADE';
EXCEPTION WHEN undefined_table THEN
RAISE EXCEPTION 'your own exception, when you like';
END;
Regards
Pavel
2012/4/2 leaf_yxj :
> I
I tried to create function to truncate table
1) when the user call the function just specify the tablename
2) the user can use the function owner privilege to execute the function.
But I got the errors as follows. Please help me to take a look.
Thanks.
Regards.
Grace
-- function :
CREA