Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2542 connectés 

  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [postgresql] trigger, j'ai du mal

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[postgresql] trigger, j'ai du mal

n°583639
GUG
Posté le 05-12-2003 à 10:52:02  profilanswer
 

Bonjour,  
Je dois recuperer a partir d'une table FACTURERCLI, la quantite (qtefactcli) d'un produit et mettre a jour la table produit (idprod, qtestock)
 
j'ai essaye plusieurs choses mais c'est un peu la choucroute :

Code :
  1. create trigger tgfactcli
  2. AFTER INSERT
  3. on FACTURERCLI FOR EACH ROW
  4. (
  5.    IF new:qtefactcli < (select qtestock from produit pd where pd.idprod = new:idprod;)
  6.    then update produit set qtestock=qtestock-new:qtefactcli from produit pd where pd.idprod=new:idprod;
  7.    end if;
  8. );


 
 
 
Je n'arrive pas à savoir si postgres comprend new:blabal  ?
si ce n est pas possible il faut alors que je passe par une procedure et ce que je veux faire sans les new: est ...
 
si vous pouviez prendre le temps de m'aider ;)  
 
merci d avance


Message édité par GUG le 05-12-2003 à 10:52:18
mood
Publicité
Posté le 05-12-2003 à 10:52:02  profilanswer
 

n°583647
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 05-12-2003 à 11:00:11  profilanswer
 

GUG a écrit :


Je n'arrive pas à savoir si postgres comprend new:blabal  ?
si ce n est pas possible il faut alors que je passe par une procedure et ce que je veux faire sans les new: est ...
 
si vous pouviez prendre le temps de m'aider ;)  
 
merci d avance


c'est new.blabla


Message édité par Harkonnen le 05-12-2003 à 11:00:35
n°583649
Mara's dad
Yes I can !
Posté le 05-12-2003 à 11:01:28  profilanswer
 

T'as pas regardé la doc toi :/
 
http://www.postgresql.org/docs/7.3 [...] igger.html


---------------
Laissez l'Etat dans les toilettes où vous l'avez trouvé.
n°583661
GUG
Posté le 05-12-2003 à 11:06:47  profilanswer
 

bah si justment ... :/  
mais j ai mal lu  
merci new.

n°583678
GUG
Posté le 05-12-2003 à 11:20:44  profilanswer
 

que veux dire  
return type trigger is only a shell (lors de la creation de fonction)
et
ERROR:  CreateTrigger: function fcfactcli() must return OPAQUE
 
merci d avance

n°583682
Harkonnen
Modérateur
Un modo pour les bannir tous
Posté le 05-12-2003 à 11:23:26  profilanswer
 

GUG a écrit :

que veux dire  
return type trigger is only a shell (lors de la creation de fonction)
et
ERROR:  CreateTrigger: function fcfactcli() must return OPAQUE
 
merci d avance
 


chaque fonction utilisée comme trigger doit retourner le type OPAQUE, c'est obligatoire

n°583700
GUG
Posté le 05-12-2003 à 11:45:01  profilanswer
 

j ai trouver ca sur opaque  
 

Code :
  1. * Sometimes OPAQUE means "this function doesn't return anything at all",
  2.   similarly to "returns void" in C and some other languages.
  3. * Sometimes OPAQUE means "this value can be any datatype at all" (eg,
  4.   input of the count() aggregate).
  5. * Sometimes OPAQUE means "I know exactly what this should be, but it's
  6.   an internal datatype with no SQL-level equivalent".  This is usually
  7.   what's at stake with a trigger function.
  8. * Sometimes OPAQUE means "I know exactly what this should be, but I
  9.   haven't declared it yet" (ie, a forward reference).  This is needed
  10.   to declare I/O functions of user-defined types, since the system
  11.   requires the functions to already exist when the type is declared.


 
 
j ai fait ca :  
 

Code :
  1. create or replace  FUNCTION fcfactcli () RETURNS TRIGGER AS '
  2. BEGIN
  3.     IF    NEW.qtefactcli <  (select qtestock from produit pd where pd.idprod = NEW.idprod;)
  4.     then
  5.          update produit set qtestock=qtestock-NEW.qtefactcli from produit pd where pd.idprod=NEW.idprod;
  6.     end if;
  7. RETURN 0;
  8. END;
  9. ' LANGUAGE 'plpgsql';


 
ca me repond :
NOTICE:  return type trigger is only a shell
CREATE
 
 
je cree le trigger :  
 

Code :
  1. create trigger tgfactcli
  2. AFTER INSERT
  3. on FACTURERCLI FOR EACH ROW
  4. EXECUTE PROCEDURE fcfactcli();


 
et la ca me repond :  
ERROR:  CreateTrigger: function fcfactcli() must return OPAQUE
 
 
j'ai essayé avec RETURN NEW;
ca fait pareille ... alors je comprend pas vraiment ... pourquoi retourner un 0 c'est pas bon ?


Message édité par GUG le 05-12-2003 à 11:50:22
n°583705
GUG
Posté le 05-12-2003 à 11:48:44  profilanswer
 

bon je suis un boulet et un gros  
remplace  
create or replace  FUNCTION fcfactcli () RETURNS TRIGGER AS '
 
par
create or replace  FUNCTION fcfactcli () RETURNS OPAQUE AS '
 
merci a tous :)
 
mainteant faut que je fasse une zolie fonction qui marche bien


Message édité par GUG le 05-12-2003 à 11:50:45

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  SQL/NoSQL

  [postgresql] trigger, j'ai du mal

 

Sujets relatifs
Tuning Postgresql - Tips[Postgresql] Transaction : équivalent à @@error en sql server ?
[PostgreSQL] phpPgAdmin, probleme de creation de table o_Oproblème de création de fonction avec postgresql 7.3.4
[Oracle Trigger] il marche pas, je c pas pkoipostgresql : afficher toutes les tables, je ne trouve pas dans la doc
différence entre postgresql et mysql [résolu merci]Trigger sous MYSQL
duplication bidirectionnelle postgresql et mysql[MySQL] trigger
Plus de sujets relatifs à : [postgresql] trigger, j'ai du mal


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR