Re: IF EXISTS

From: david techer <davidtecher(at)yahoo(dot)fr>
To: "P(dot)M" <pmdanger(at)yahoo(dot)com>, PostgreSQL FR <pgsql-fr-generale(at)postgresql(dot)org>
Subject: Re: IF EXISTS
Date: 2005-11-20 12:53:48
Message-ID: 438071DC.2090701@yahoo.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

Bonjour

Personnellement je n'ai encore eu le temps de tester la 8.1.0 pour
savoir celà!

Ayant que la 8.0.4 d'installée sur ma bécane, j'utilise la fonction
suivante si celà peux-vous intéresser pour tester si une table existe et
l'effacer le cas éventuel:

select drop_table_if_exists('matable', false);

dont la synthaxe est:

CREATE OR REPLACE FUNCTION drop_table_if_exists(text, bool) RETURNS text AS '
DECLARE
opt text;
rec record;
BEGIN
IF $2 THEN
opt := '' CASCADE'';
ELSE
opt := '''';
END IF;

IF NULLVALUE($1) THEN

RETURN ''ATTENTION: Table non trouvée'';

ELSE

SELECT INTO rec tablename FROM pg_tables WHERE tablename like $1;

IF FOUND THEN
EXECUTE ''DROP TABLE '' || $1 || opt;
RETURN ''Effacement de la table ''|| $1 || ''...OK'';
END IF;

END IF;

RETURN ''ATTENTION: Table ''|| $1 || '' non trouvée'';

END;
' LANGUAGE 'plpgsql';

--david;
-------------------------------------------------
Jean David TECHER
e-mail: davidtecher(at)yahoo(dot)fr
site: http://techer.pascal.free.fr/postgis/
-------------------------------------------------

P.M a écrit :

> Bonjour a tous,
>
> J'aimerai savoir si la commande IF EXISTS, existe sous PostgreSQL 8.1
> car je n'ai rien trouve de tel jusqu'a present lorsque je desire faire
> un DROP.
>
> Quelqu'un pourrait-il m'aider SVP ?
> merci,
>
> Maileen
>
> ------------------------------------------------------------------------
> Yahoo! FareChase - Search multiple travel sites in one click.
> <http://us.lrd.yahoo.com/_ylc=X3oDMTFqODRtdXQ4BF9TAzMyOTc1MDIEX3MDOTY2ODgxNjkEcG9zAzEEc2VjA21haWwtZm9vdGVyBHNsawNmYw--/SIG=110oav78o/**http%3a//farechase.yahoo.com/>

In response to

Responses

Browse pgsql-fr-generale by date

  From Date Subject
Next Message thomas.silvi 2005-11-20 13:00:16 Re: tableau procédure
Previous Message P.M 2005-11-20 12:43:56 IF EXISTS