Обсуждение: checking schema present or not by passing schema name as parameter

Поиск
Список
Период
Сортировка

checking schema present or not by passing schema name as parameter

От
anushasrivastava03
Дата:
i am checking if schema present or not and passing schema name dynamically
but it's trowing an error :


CREATE OR REPLACE FUNCTION chkschema(schemaname text)
  RETURNS boolean AS
$BODY$
DECLARE
   i boolean;
BEGIN

    EXECUTE 'SELECT exists(select schema_name FROM information_schema.schemata
WHERE schema_name = '||quote_ident(schemaname)||')'
    INTO    i ;

IF i THEN

    return i;
else

    return i;
end if;

end;
$BODY$
  LANGUAGE plpgsql

ERROR:  column "secc_master" does not exist
LINE 1: ...M information_schema.schemata WHERE schema_name = secc_maste...
                                                             ^






--
View this message in context:
http://postgresql.1045698.n5.nabble.com/checking-schema-present-or-not-by-passing-schema-name-as-parameter-tp5758131.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.


Re: checking schema present or not by passing schema name as parameter

От
Pavel Stehule
Дата:
Hello

2013/6/6 anushasrivastava03 <anushasrivastava03@yahoo.co.in>:
> i am checking if schema present or not and passing schema name dynamically
> but it's trowing an error :
>
>
> CREATE OR REPLACE FUNCTION chkschema(schemaname text)
>   RETURNS boolean AS
> $BODY$
> DECLARE
>    i boolean;
> BEGIN
>
>         EXECUTE 'SELECT exists(select schema_name FROM information_schema.schemata
> WHERE schema_name = '||quote_ident(schemaname)||')'
>         INTO    i ;

why do you use EXEC there

do only

BEGIN
  IF EXISTS(SELECT * FROM information_schema.schemata WHERE
schema_name = 'secc_master'_ THEN
   ...
  ELSE
   ...
  END IF;



>
> IF i THEN
>
>         return i;
> else
>
>         return i;
> end if;
>
> end;
> $BODY$
>   LANGUAGE plpgsql
>
> ERROR:  column "secc_master" does not exist
> LINE 1: ...M information_schema.schemata WHERE schema_name = secc_maste...

you have to use quote_literal function there, not quote_ident.

Regards

Pavel

>                                                              ^
>
>
>
>
>
>
> --
> View this message in context:
http://postgresql.1045698.n5.nabble.com/checking-schema-present-or-not-by-passing-schema-name-as-parameter-tp5758131.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


Re: checking schema present or not by passing schema name as parameter

От
anushasrivastava03
Дата:
thanks 'quote_literal' worked :)



--
View this message in context:
http://postgresql.1045698.n5.nabble.com/checking-schema-present-or-not-by-passing-schema-name-as-parameter-tp5758131p5758251.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.