Re: trouble with query - Mailing list pgsql-sql

From jasiek@klaster.net
Subject Re: trouble with query
Date
Msg-id 20030319184927.GA29082@serwer.skawsoft.com.pl
Whole thread Raw
In response to trouble with query  ("alexj" <alexj@freesurf.ch>)
List pgsql-sql
On Tue, Mar 18, 2003 at 03:47:55PM +0100, alexj wrote:
> Hi,
> 
> I'm looking how can I do to insert multiple values from a
> complexe query.
> 
> What I want to do is something like that :
> 
> INSERT INTO est_planifie_jour (id,ref_activite,ref_ressource,ref_jour)
>  (SELECT nextval('est_p_id_p') FROM est_planifie),
>  (SELECT id_activite FROM activite WHERE
>  nom = 'SGBD 02 cours théorique),
> (SELECT ref_ressource FROM personne,groupe,fait_partie
>  WHERE groupe.nom ='cycle 1b' AND
>  fait_partie.ref_groupe = groupe.id_groupe AND
> personne.id_personne = fait_partie.ref_personne),
> (SELECT id_jour FROM jour WHERE jour.id_jour = 3)
>
You should rewrite your insert to receive multiple rows from single
select. This query shoud be similiar to this below:

insert into ... (..)
selectnextval('est_p_id_p'),id_activite,ref_resource,ref_jour
fromactivite, personne,groupe,fait_partie,jour
whereactivite.nom='..' and fait_partie.ref_groupe=groupe.id_groupeand groupe.nom='..'and jour.id_jour=3

Regards,
Tomasz Myrta


pgsql-sql by date:

Previous
From: "alexj"
Date:
Subject: trouble with query
Next
From: "jack"
Date:
Subject: Re: the best way to get some records not in another table