Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 969DD632377 for ; Fri, 20 Aug 2010 05:44:45 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 73687-05 for ; Fri, 20 Aug 2010 08:44:38 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.gmx.net (mailout-de.gmx.net [213.165.64.22]) by mail.postgresql.org (Postfix) with SMTP id 8E092632416 for ; Fri, 20 Aug 2010 05:44:37 -0300 (ADT) Received: (qmail 10029 invoked by uid 0); 20 Aug 2010 08:44:35 -0000 Received: from 192.124.237.7 by www003.gmx.net with HTTP; Fri, 20 Aug 2010 10:44:34 +0200 (CEST) Content-Type: text/plain; charset="utf-8" Date: Fri, 20 Aug 2010 10:44:33 +0200 From: "Jan-Peter Seifert" Message-ID: <20100820084433.243470@gmx.net> MIME-Version: 1.0 Subject: query fine in psql/pgAdmin III but error message when within plpgsql function To: pgsql-admin@postgresql.org X-Authenticated: #955937 X-Flags: 0001 X-Mailer: WWW-Mail 6100 (Global Message Exchange) X-Priority: 3 X-Provags-ID: V01U2FsdGVkX1/19w9MeXD1H+YmEMMTZ0FyrWzhPKIXaxG/4JiQ6b dvRddHSCiq8KsBCDzxB6URMoQaIZ5FegWMCw== Content-Transfer-Encoding: 8bit X-GMX-UID: RXJXdC1qYW0tRkXlb2ZpSWB8amthc5u8 X-FuHaFi: 0.58999999999999997 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201008/137 X-Sequence-Number: 35386 Hello, I thought I had some experience with plpgsql functions by now. However, when trying to do this query (generic column/table names): UPDATE table_a cus SET spalte1 = ( SELECT spalte1 FROM table_a_copy cl WHERE cl.tabname = cus.tabname ); from within a plpgsql funtion I get the error message: 'more than row returned by a subquery used as an expression'. This even happens when I put the query into a string that I let be EXECUTEed. I works without errors and seemingly the way I wanted when doing the update separately. Before I create a copy of table_a with: CREATE TABLE table_a_copy AS SELECT * FROM table_a; Then I load the backed up data with COPY to table_a_copy. Then I do the update(s). Of course one could do the updates with a loop, but in my opinion that's rather inconvenient. Any hints what the problem is? Thank you very much, Peter P.S. Server version 8.3.11. The name of the schema is different from public so I'm using 'set search_path TO ...'. -- GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT! Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01