Re: ordre

From: "J(dot)Pierre Pourrez" <ptc1(at)free(dot)fr>
To: pgsql-fr-generale(at)postgresql(dot)org
Subject: Re: ordre
Date: 2005-03-03 11:24:05
Message-ID: pan.2005.03.03.11.24.04.566566@free.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-fr-generale

Le Thu, 03 Mar 2005 11:02:03 +0100, J.Pierre Pourrez a écrit :

> Reste à savoir si on tient absolument à ce que ordre soit affiché à
> partir de 1 pour chaque facture.
>
> -----------8<--------8<------------8<-----------------
>CREATE TABLE ligne (
> id serial PRIMARY KEY,
> art_id character(6) NOT NULL,
> lig_qte integer NOT NULL,
> art_prix integer ,
> fac_id integer NOT NULL
> );
>
> -- on crée un petit jeu d'essai
> INSERT INTO ligne(fac_id, art_id,lig_qte,art_prix)
> values(1,'PCR06CO',3,34);
> INSERT INTO ligne(fac_id, art_id,lig_qte,art_prix)
> values(1,'PCR06C',3,34);
> INSERT INTO ligne(fac_id, art_id,lig_qte,art_prix)
> values(1,'PCR06D',6,54);
> INSERT INTO ligne(fac_id, art_id,lig_qte,art_prix)
> values(1,'PCR06E',10,88);
> INSERT INTO ligne(fac_id, art_id,lig_qte,art_prix)
> values(2,'PBR06E',30,82);
> INSERT INTO ligne(fac_id, art_id,lig_qte,art_prix)
> values(2,'PBS06E',45,108);
> INSERT INTO ligne(fac_id, art_id,lig_qte,art_prix)
> values(2,'PBS16E',25,99);
>
> -- table bidon pour donner un format à la sortie de la fonction facture
> CREATE TABLE ligne_detail (id integer, art_id char(6), lig_qte integer,
> art_prix integer);
>
> -- renumérotation des lignes de la facture à partir de 1 CREATE
> FUNCTION facture(integer) RETURNS SETOF ligne_detail
> AS 'select
> id-(SELECT MIN(id) FROM ligne WHERE fac_id=$1)+1, art_id, lig_qte,
> art_prix FROM ligne WHERE fac_id=$1 ORDER BY id;' LANGUAGE sql;
>
> -- afficher les lignes de la facture n°2 select * from facture(2);
>
> ----------8<-----8<---------8---------------------------------------

J'ai oublié d'afficher les résultats:

facture=> select * from ligne;
id | art_id | lig_qte | art_prix | fac_id
----+--------+---------+----------+--------
1 | PCR06C | 3 | 34 | 1
2 | PCR06D | 6 | 54 | 1
3 | PCR06E | 10 | 88 | 1
4 | PBR06E | 30 | 82 | 2
5 | PBS06E | 45 | 108 | 2
6 | PBS16E | 25 | 99 | 2
(6 lignes)

facture=> select * from facture(2);
id | art_id | lig_qte | art_prix
----+--------+---------+----------
1 | PBR06E | 30 | 82
2 | PBS06E | 45 | 108
3 | PBS16E | 25 | 99
(3 lignes)

En espérant que cela aide
Jean-Pierre

In response to

  • Re: ordre at 2005-03-03 10:02:03 from J.Pierre Pourrez

Responses

Browse pgsql-fr-generale by date

  From Date Subject
Next Message Stephane Bunel 2005-03-03 23:00:06 invalid multibyte character for locale
Previous Message J.Pierre Pourrez 2005-03-03 10:02:03 Re: ordre