Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id 264739FC08D for ; Thu, 28 Jun 2007 03:28:42 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 58736-04 for ; Thu, 28 Jun 2007 03:28:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.183]) by postgresql.org (Postfix) with ESMTP id 8A6A29FC079 for ; Thu, 28 Jun 2007 03:28:29 -0300 (ADT) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu5) with ESMTP (Nemesis), id 0ML25U-1I3nUR0rQz-0006DA; Thu, 28 Jun 2007 08:28:27 +0200 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1I3nUQ-0006Lq-00 for pgsql-performance@postgresql.org; Thu, 28 Jun 2007 08:28:26 +0200 Date: Thu, 28 Jun 2007 08:28:26 +0200 From: "A. Kretschmer" To: pgsql-performance@postgresql.org Subject: Re: update query taking too long Message-ID: <20070628062826.GC22066@a-kretschmer.de> References: <46834124.5010600@gmail.com> <21072.1183009270@sss.pgh.pa.us> <46835252.5070901@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46835252.5070901@gmail.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX18+L5+lOn8S9NU40JyFBKhT7TunxWPqKAlHHbx fHrdP6YxJd2gqxBroT0cnXyYlQ5+ZaTd+IKcVSOfw1ZTUlWHKe +PgFp5wda02MOyzx8DprHDEi7VyJGe8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/614 X-Sequence-Number: 25647 am Thu, dem 28.06.2007, um 16:16:50 +1000 mailte Chris folgendes: > Is there a better way to write the update? I thought about something > like this (but couldn't get it working - guess I don't have the right > syntax): > > update t1 set domainname=(select id, SUBSTRING(emailaddress FROM > POSITION('@' IN emailaddress)) from table t2) AS t2 where t1.id=t2.id test=# select * from foo; id | mail | domain ----+-------------+-------- 1 | foo@foo.tld | 2 | bar@bar.tld | (2 rows) test=*# update foo set domain=SUBSTRING(mail FROM (POSITION('@' IN mail)+1)); UPDATE 2 test=*# select * from foo; id | mail | domain ----+-------------+--------- 1 | foo@foo.tld | foo.tld 2 | bar@bar.tld | bar.tld (2 rows) (without the @ in the domain...) Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net