Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id EB53C9FB3F1 for ; Sun, 25 Feb 2007 19:57:50 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 44555-03 for ; Sun, 25 Feb 2007 19:57:42 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.174]) by postgresql.org (Postfix) with ESMTP id 99B359FB3B5 for ; Sun, 25 Feb 2007 19:57:46 -0400 (AST) Received: by ug-out-1314.google.com with SMTP id k3so579336ugf for ; Sun, 25 Feb 2007 15:57:45 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=FQTLbQkMjay472r2KXZMFrYnaMVqPdzFTNsBoEYY2TrAJ1gZ8HgkSx57j9Sh3+4Luh9RMlMp2A+rbbp43OI/Amm/ISqKw9fptVIqaBrw8/CVWMwqCZZ8aG44kGrjyOG2S8sQw+L5Zj8yg7gcm+2WhNFq6uLiVTW4WF5hnayILt4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=LAPggc2Ranx9mBRKfHinWrg/9l1a44REurdqE482Kh16oY7zifD7jBguXF45XhH3y1EeMAavQm4BWNOX7Mwc4ueiqQTmi9Dk0/Cd+HAwyJN6uC5v8rQBUbZox42eSGsyLH86H5gYjAcUY+m7P5In/4AolhsxX0XCL/TZ5JWdo34= Received: by 10.67.22.14 with SMTP id z14mr5561374ugi.1172447865196; Sun, 25 Feb 2007 15:57:45 -0800 (PST) Received: by 10.67.94.13 with HTTP; Sun, 25 Feb 2007 15:57:45 -0800 (PST) Message-ID: <55c095e90702251557v3cc96b10m10b28c98ca8c89ee@mail.gmail.com> Date: Sun, 25 Feb 2007 20:57:45 -0300 From: "Ezequias Rodrigues da Rocha" To: "Phillip Smith" Subject: Re: Insert based in a select Cc: pgsql-sql@postgresql.org In-Reply-To: <008301c7592a$bfed31c0$9b0014ac@wbaus090> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_54233_1462857.1172447865145" References: <55c095e90702250543w6bd52882yafe24498959d0788@mail.gmail.com> <008301c7592a$bfed31c0$9b0014ac@wbaus090> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/259 X-Sequence-Number: 27593 ------=_Part_54233_1462857.1172447865145 Content-Type: text/plain; charset=WINDOWS-1252; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The second statement works but only 1 row was affected. It do not apply to me. The first statement i didn't understand. You are adding only the first fiel= d on my base.ingresso table ? Regards Ezequias 2007/2/25, Phillip Smith : > > (Please reply to the list when replying) > > > > The error is correct =96 you are telling PG to insert one row (the litera= l > values you've passed to INSERT), but the sub-query is returning multiple > rows which won't fit in a single row. > > > > I see 2 options, but someone else I'm sure will have a more elegant way t= o > do it: > > 1) insert into base.ingresso (select id from base.cartao order by id) > > 2) insert into base.ingresso values (nextval(' base.ingresso_id'), 4, > now(), 12.34, 12.34, 1, 1678, (select id from base.cartao where id not in > (SELECT id from base.ingresso) order by id limit 1), 2, 25, 99) > > > > Number 1 will create one row in base.ingresso for each row in base.cartao= . > You will then need to use UPDATE to adjust the values in each of those ro= ws > to the other values you want. > > > > Number 2 would need to be run over and over again =96 not a practical opt= ion > I imagine=85 > > > > ~p > > > > -----Original Message----- > *From:* Ezequias Rodrigues da Rocha [mailto:ezequias.rocha@gmail.com] > *Sent:* Monday, 26 February 2007 00:43 > *To:* phillip.smith@weatherbeeta.com.au > *Subject:* Re: [SQL] Insert based in a select > > > > Phillip, > > Thank you for the information but the master (id) is only a field of my > secondary table. > > My sql statement is like this: > > *insert into base.ingresso values (nextval(' base.ingresso_id'), 4, now()= , > 12.34, 12.34, 1, 1678, (select id from base.cartao order by id), 2, 25, > 99)* > > And I am getting the following error return message: > > *ERROR: more than one row returned by a subquery used as an expression > SQL state: 21000 > * > Could you give me another help with this ? > > Ezequias > > ********************Confidentiality and Privilege > Notice******************** > > The material contained in this message is privileged and confidential to > the addressee. If you are not the addressee indicated in this message or > responsible for delivery of the message to such person, you may not copy = or > deliver this message to anyone, and you should destroy it and kindly noti= fy > the sender by reply email. > > Information in this message that does not relate to the official business > of Weatherbeeta must be treated as neither given nor endorsed by > Weatherbeeta. Weatherbeeta, its employees, contractors or associates shal= l > not be liable for direct, indirect or consequential loss arising from > transmission of this message or any attachments > > --=20 =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D Atenciosamente (Sincerely) Ezequias Rodrigues da Rocha =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- A pior das democracias ainda =E9 melhor do que a melhor das ditaduras The worst of democracies is still better than the better of dictatorships http://ezequiasrocha.blogspot.com/ ------=_Part_54233_1462857.1172447865145 Content-Type: text/html; charset=WINDOWS-1252 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline The second statement works but only 1 row was affected. It do not apply to = me.

The first statement i didn't understand. You are adding only= the first field on my base.ingresso table ?

Regards
Ezequias

2007/2/25, Phillip Smith <phillip.smith@weatherbeeta.co= m.au>:

(Please reply to the list when rep= lying)

 

The error is correct =96 you are telling PG to insert one row (the literal values you've passed to INSERT), but the sub-query is returning multiple rows which won't fit in a single row.

 

I see 2 options, but someone else = I'm sure will have a more elegant way to do it:

1) insert into base.ingresso (sele= ct id from base.cartao order by id)

2) insert into base.ingresso value= s (nextval(' base.ingresso_id'), 4, now(), 12.34, 12.34, 1, 1678, (select id from ba= se.cartao where id not in (SELECT id from base.ingresso) order by id limit 1), 2, 25,= 99)

 

Number 1 will create one row in ba= se.ingresso for each row in base.cartao. You will then need to use UPDATE to adjust the values in each of those rows to the other values you want.

 

Number 2 would need to be run over= and over again =96 not a practical option I imagine=85

 

~p

 

-----Original Message-----
From: Ezequias Rodrigues d= a Rocha [mailto:ezequias.rocha@gmail.co= m]
Sent:
Monday, 26 February 2007 00:43
To: phillip.smith@weatherb= eeta.com.au
Subject: Re: [SQL] Insert = based in a select

<= span style=3D"font-size: 12pt;"> 

<= span style=3D"font-size: 12pt;">Phillip,

Thank you for the information but the master (id) is only a field of my secondary table.

My sql statement is like this:

insert into base.ingresso values (nextval(' base.ingresso_id'), 4, now(), = 12.34, 12.34, 1, 1678, (select id from base.cartao order by id), 2, 25, 99)=

And I am getting the following error return message:

ERROR: more than one row returned by = a subquery used as an expression
SQL state: 21000

Could you give me another help with this ?

Ezequias


*******************Confidentiality and Privilege Notice*****************= **

The material contained in this message is privileged and confidential to the addressee. If you are not the addressee indicated in this message or responsible for delivery of the message to such person, you may not copy or deliver this message to anyone, and you should destroy it and kindly notify the sender by reply email.

Information in this message that does not relate to the official business of Weatherbeeta must be treated as neither given nor endorsed by Weatherbee= ta. Weatherbeeta, its employees, contractors or associates shall not be liable for direct, indirect or consequential loss arising from transmission of thi= s message or any attachments




--
=3D-=3D-=3D-=3D-=3D-= =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D
      = ;            &n= bsp;            = ;   Atenciosamente (Sincerely)
    &n= bsp;            = ;       Ezequias Rodrigues da Rocha
=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-= =3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D= -
A pior das democracias ainda =E9 melhor do que a melhor das ditaduras<= br>The worst of democracies is still better than the better of dictatorship= s
http://ezequiasrocha.blo= gspot.com/ ------=_Part_54233_1462857.1172447865145--