Sunday, August 31, 2008

Re: [pgsql-fr-generale] ERREUR: "$3" is declared CONSTANT

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

--
Sent via pgsql-fr-generale mailing list (pgsql-fr-generale@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-fr-generale

No comments: