Skip site navigation (1) Skip section navigation (2)

Re: ERREUR: "$3" is declared CONSTANT

From: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
To: Samuel ROZE <samuel(dot)roze(at)aliceadsl(dot)fr>
Cc: pgsql-fr-generale(at)postgresql(dot)org
Subject: Re: ERREUR: "$3" is declared CONSTANT
Date: 2008-08-31 21:10:52
Message-ID: 48BB08DC.8090300@lelarge.info (view raw or flat)
Thread:
Lists: pgsql-fr-generale
Samuel ROZE a écrit :
> [...]
> Maintenant, voici le code de ma fonction "contact" :
> 
> -------------------------
> CREATE OR REPLACE FUNCTION clients.contact (p_nom text, p_email text,
> p_t integer) RETURNS integer AS $contact$
> DECLARE
>     v_id integer DEFAULT 0;
> BEGIN
>     IF (p_t != 0) THEN
>         p_t := 1;
>     END IF;
>     SELECT id INTO v_id FROM clients.contacts WHERE nom = p_nom AND
> email = p_email LIMIT 1;
>     IF NOT FOUND THEN
>         INSERT INTO clients.contacts (nom, email, _trigger) VALUES
> (p_nom, p_email, p_t);
>         SELECT id INTO v_id FROM clients.contacts WHERE nom = p_nom AND
> email = p_email LIMIT 1;
>     END IF;
>     RETURN v_id;
> END;
> $contact$ language plpgsql;
> -------------------------
> 

Rien à voir avec ta question, mais juste pour infos, si tu utilises une
version 8.2 ou supérieure, tu peux remplacer :

INSERT INTO clients.contacts (nom, email, _trigger) VALUES (p_nom,
p_email, p_t);
SELECT id INTO v_id FROM clients.contacts WHERE nom = p_nom AND
email = p_email LIMIT 1;

par

INSERT INTO clients.contacts (nom, email, _trigger) VALUES (p_nom,
p_email, p_t) RETURNING id INTO v_id;


-- 
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com

In response to

Responses

pgsql-fr-generale by date

Next:From: Samuel ROZEDate: 2008-08-31 21:17:10
Subject: Re: ERREUR: "$3" is declared CONSTANT
Previous:From: Samuel ROZEDate: 2008-08-31 17:49:17
Subject: Re: ERREUR: "$3" is declared CONSTANT

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group