Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 2984F2D0B11 for ; Fri, 10 Feb 2012 12:09:02 -0400 (AST) Received: from smtp107.prem.mail.ac4.yahoo.com ([76.13.13.46]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Rvt1u-0007bb-Hn for pgsql-sql@postgresql.org; Fri, 10 Feb 2012 16:09:01 +0000 Received: (qmail 92800 invoked from network); 10 Feb 2012 16:08:43 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=ZDcq2737+UlwQm11y20DHAhTnpUDscJKxx1NZm/ynoG6RjCtJDLFDaikvYHw1MnzpsunHnlvweJlXFA8IIK4uMt0x3SQXk5oOI6AOrG0Et361RKQdWjg5MsbYiy19FCKFJGqnZMi3TBgzo4Blr6QXXo0UE/ZXt3m6eld/6YZqLs= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1328890123; bh=AYjEP3K6gBvfs1ys5zu2g9u/aGbSCgKSAnsh5y0Gs1s=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=noHZcKCMffwsiq/XdQj389/Mvp1kq5bDz4fZTj/q2hwcznf27Dj4cShzpPJgMVAbUHtGZ6x3EN7Cj7qiRjhxnzK4dF4kQ0ZzhUPCllV/2mEfz5FcjXBcIHiVjfwiI46Nm0tNZOZ9jyiunx6h9ljHZp2QTfnFpC/BMl2kjIvJ31w= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: zRtve3IVM1lGSrEGK85DlI.EYR4BNgzXXk2GTO4Vo9mf.wG I8Y0JKk0Me34Y0_KIv_9p3tNue6fSBBkcZYras.NlFyPL8kv5diRd4FqXyIW 7cx2XeMQ6CyAY_aVL6vXQ3zOBwA5BxiJd1nfBAKbvzw0zz28lWeV6s2e7.O5 sLpVB7o6fEw3cl2QTH9vgvpmyrPbQ4HadsOaUHtYuHntxVp.bQubWyKGtu_q R_1qNTx9rdeCRABQaG8BPgb5edHyAS4jYuWw.3VXKgTJr7vEo3zIE.j3Bkzg RIaXI4Z0aliixxowdXsT5upijDRH_6IFK0GZNI3zhLBzhTxdNvtbw3JmMtID PHIOQPu_qbSb_tkwOoj6QiNqSGgIR0wv.chw4fr7fqIGG6Tho7zAUsHrxSLZ V2lhgfNYLlnjePpSObUMp X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp107.prem.mail.ac4.yahoo.com with SMTP; 10 Feb 2012 08:08:43 -0800 PST From: "David Johnston" To: "'ssylla'" , References: <1328754679303-5468395.post@n5.nabble.com> In-Reply-To: <1328754679303-5468395.post@n5.nabble.com> Subject: Re: update column with multiple values Date: Fri, 10 Feb 2012 11:08:11 -0500 Message-ID: <033b01cce80e$30313860$9093a920$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQLh2MuemLcwJ91qyQOe1/fTb+YlrJQMaiQg Content-Language: en-us X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201202/37 X-Sequence-Number: 36330 -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of ssylla Sent: Wednesday, February 08, 2012 9:31 PM To: pgsql-sql@postgresql.org Subject: [SQL] update column with multiple values Dear list, sorry, I already posted this, but it did not seem to have been accepted by the mailing list. So here's my second try: I need to update all rows of a column ('parent') based on a subquery that returns me the first four digits of another column ('id'): UPDATE admin SET parent=(SELECT SUBSTR(id,1,4) FROM admin); After executing, I get the following error-message: "more than one row returned by a subquery used as an expressionmore than one row returned by a subquery used as an expression" I am not quite sure about that, but maybe I need to construct a function/loop to fulfill this task? thanks for help. Stefan --------------------------------------------------------------- No sub-select required, just use the function: UPDATE admin SET parent = substr(id,1,4); This will, for each record, set the value of parent to the first four characters of its ID. When you use the sub-select there is not inherent linkage between the "UPDATE" table and the "FROM" table. You can make a correlated sub-query but in this case the is necessary. David J.