Précédent   Forum des professionnels en informatique > Bases de données > PostgreSQL
PostgreSQL Forum PostgreSQL. Avant de poster -> F.A.Q PostGreSQL Tutoriels PostGreSQL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 22/04/2004, 15h10   #1
Membre du Club
 
Inscription : mars 2004
Messages : 89
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 89
Points : 59
Points : 59
Par défaut Pbleme UPDATE sur POSTGRESQL

Bonjour tout le monde,

je cherche à faire une incrémentation par un UPDATE (je ne vais pas trop m'attarder sur le pourquoi car ca serait un peu long) , mon objectif est qu'a chaque fois que je rentre un article dans ma table "articles_tbl" un attribut 'numero' de la table "deposants_tbl" s'incremente. C'est le deposant qui depose l'article donc cette incrementation doit être faite sur sa ligne (où il a un id_deposant en clé primaire).

Le probleme actuel est que qd je lance cet UPDATE, l'attribut 'numero' de la table deposants_tbl s'incrémente sur tous les deposants et non sur le concerné.

Voila mon code:

UPDATE ONLY deposants_tbl
SET numero=deposants_tbl.numero+1
FROM deposants_tbl AS d, articles_tbl AS a
WHERE a.id_articles=(select max(id_articles) from articles_tbl) AND
a.id_deposant=d.id_deposant;


MERCI
$grm$ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/04/2004, 15h12   #2
Membre du Club
 
Inscription : mars 2004
Messages : 89
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 89
Points : 59
Points : 59
Par défaut ma table articles

Table "public.articles_tbl"
Colonne | Type | Modifications
----------------+-------------------+---------------
id_articles | integer | not null
id_deposant | integer |
id_geographie | integer |
id_employe | integer |
id_famille | integer |
description | text | not null
observation | text | not null
assure | boolean | not null
cle | boolean | not null
id_fournisseur | integer |
id_article | character varying |
Index: articles_tbl_pkey primary key btree (id_articles)
Foreign Key constraints: FK_deposant FOREIGN KEY (id_deposant) REFERENCES deposants_tbl(id_deposant) ON UPDATE RESTRICT ON DELETE RESTRICT,
FK_employe FOREIGN KEY (id_employe) REFERENCES employes_tbl(id_employe) ON UPDATE RESTRICT ON DELETE RESTRICT,
FK_famille FOREIGN KEY (id_famille) REFERENCES famille_tbl(id_famille) ON UPDATE RESTRICT ON DELETE RESTRICT,
FK_geo FOREIGN KEY (id_geographie) REFERENCES geographie_tbl(id_geographie) ON UPDATE RESTRICT ON DELETE RESTRICT,
FK_fournisseur FOREIGN KEY (id_fournisseur) REFERENCES fournisseurs_tbl(id_fournisseur) ON UPDATE RESTRICT ON DELETE RESTRICT
$grm$ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 22/04/2004, 15h13   #3
Membre du Club
 
Inscription : mars 2004
Messages : 89
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 89
Points : 59
Points : 59
Par défaut table deposants

Table "public.deposants_tbl"
Colonne | Type | Modifications
--------------+-------------------+---------------
id_deposant | integer | not null
cp | integer |
societe | character varying |
nom | character varying | not null
prenom | character varying | not null
adresse | text | not null
pays | character varying | not null
tel_domicile | integer | not null
tel_bureau | integer |
tel_portable | integer |
mail | character varying |
fax | integer |
observation | text |
mdp | integer | not null
blocage | boolean | not null
profession | character varying |
numero | integer |
Index: deposants_tbl_pkey primary key btree (id_deposant)
Foreign Key constraints: FK_cp FOREIGN KEY (cp) REFERENCES cp_tbl(cp) ON UPDATE RESTRICT ON DELETE RESTRICT
$grm$ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2004, 14h44   #4
Membre du Club
 
Inscription : mars 2004
Messages : 89
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 89
Points : 59
Points : 59
Personne ne veux m'aider?????


SNIFFOUILLLE
$grm$ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 23/04/2004, 15h16   #5
Modérateur
 
Avatar de al1_24
 
Homme Alain
Ingénieur d'études décisionnel
Inscription : mai 2002
Messages : 4 443
Détails du profil
Informations personnelles :
Nom : Homme Alain
Âge : 51
Localisation : France, Val de Marne (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études décisionnel
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 4 443
Points : 7 528
Points : 7 528
Par défaut Re: Pbleme UPDATE sur POSTGRESQL

Code :
1
2
3
4
5
6
UPDATE deposants_tbl 
SET numero=deposants_tbl.numero+1
FROM deposants_tbl AS d, articles_tbl AS a
WHERE a.id_articles=(SELECT max(id_articles) FROM articles_tbl) 
AND a.id_deposant=d.id_deposant
AND deposants_tbl.id_deposant=d.id_deposant;
:
al1_24 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/04/2004, 14h28   #6
Membre du Club
 
Inscription : mars 2004
Messages : 89
Détails du profil
Informations forums :
Inscription : mars 2004
Messages : 89
Points : 59
Points : 59
Il ne manquait pas grand chose mais c'est exactement pourcela que j'ai tourné en rond pendant 2 heures!!!!
Merci bcp de ton aide al1_24
$grm$ est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 26/04/2004, 14h50   #7
Modérateur
 
Avatar de al1_24
 
Homme Alain
Ingénieur d'études décisionnel
Inscription : mai 2002
Messages : 4 443
Détails du profil
Informations personnelles :
Nom : Homme Alain
Âge : 51
Localisation : France, Val de Marne (Île de France)

Informations professionnelles :
Activité : Ingénieur d'études décisionnel
Secteur : Conseil

Informations forums :
Inscription : mai 2002
Messages : 4 443
Points : 7 528
Points : 7 528
Ne pas oublier le tag [Résolu]
al1_24 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 01h45.


 
 
 
 
Partenaires

Hébergement Web