Re: Re: Please help me to take a look of the erros in my functions. Thanks.

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: leaf_yxj <leaf_yxj(at)163(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Re: Please help me to take a look of the erros in my functions. Thanks.
Date: 2012-04-03 14:09:04
Message-ID: 4F7B0480.40402@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 04/03/2012 07:01 AM, leaf_yxj wrote:
> ***********************************************************
>
> 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;
> END;
> $$
> LANGUAGE plpgsql SECURITY DEFINER STRICT;
>
> ***********************************************************
>
> This works . Thank you very much.
>
>
> ***********************************************************
>
> CREATE OR REPLACE FUNCTION truncate_t (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;
> END;
> $$
> LANGUAGE plpgsql SECURITY DEFINER STRICT;
>
> ***********************************************************
> This works,too. Thank you very much. What's the difference between ( IN
> tablename text)
> and ( tablename text).
>
>
>
> ---------- one more questions thanks.
>
>
>
> After I created the function sucessfully , I want to execute the function. I
> get errors as follows :
>
> rrp=> select truncate_t(t1);
> ERROR: column "t1" does not exist
> LINE 1 : select truncate_t(t1);
> ^

You need to pass in a text value:

select truncate_t('t1');

>
>
>
> rrp=> select truncate_t(rrp.t1);
> ERROR:missing FROM-clause entry for table "rrp"
> LINE 1 : select truncate_t(rrp.t1);
> ^

Same above.

>
>
> --
> 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-tp5613507p5615212.html
> Sent from the PostgreSQL - general mailing list archive at Nabble.com.
>

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ozgun Erdogan 2012-04-03 14:23:43 Command counter increment vs updating an active snapshot
Previous Message leaf_yxj 2012-04-03 14:08:25 Re: Please help me to take a look of the erros in my functions. Thanks.