Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 9E7F61F07123 for ; Thu, 26 Jan 2012 20:20:31 -0400 (AST) Received: from smtp106.prem.mail.sp1.yahoo.com ([98.136.44.61]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1RqZYI-0004IZ-1J for pgsql-sql@postgresql.org; Fri, 27 Jan 2012 00:20:30 +0000 Received: (qmail 5336 invoked from network); 27 Jan 2012 00:20:13 -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=R7WZZcH6hJg8YPWbJVtDk4lhGrFurjNhqVJ2VrDEzQHmVH+h5ssO3jsY7G/7I650P7IEjerCB4O7R1Y4tDJ8yVFCCoUg46PL6ZOgN/8lkWf4FbGeIZJB+zZXp2ueEPeBWKFHckoG3v51chhrcdY6OqJvblR3zrFrDzxc5vMtOYo= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1327623613; bh=nbuwBj5MfeQvWkCS8na2IBftxJKNG/vtn7or4v0/iwI=; 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=qHOuh/fU63UonjCBSAeT6RKfpBNrcf9RroKpfE34I+5NmsAYDFpQZrhMOILRBo5PulhWCX8DNrhkPM3okzhaMWVbi3rkkf6L+H+yJvF+Di/BAe0S5qKKv1WSX2QFijnANnNSnD2NI4IDGByarhIkt2OJBqrWTNVyGTOFpDV2YTg= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: mK_IznoVM1lFU_U46zhVf2Md8NZpdjWvLZ24o77UpqGci_P BoZfsjkSkSfQE6UqZv_DPAYIXVkSnwKRxwa65a7lmzLnMMrpKl6RaGmyQ6kV WfEiTIJl0EXZu6qjCQnJZ.vTUqU8bBGXbGTPFR4v9GbdR5R.7JGCcgjuoFry _9qAm03jDuMeoyOBCRkQYLiG7rT2Y.if_15WOLdbzzqOsIZkOoc6yQipEhQM sxxxtrdcZo11gN7Ii7uwX3UKA3YXM0jEw8Whl0T0sufiEB.wagPjFwLoK9tr ezyX0Je_tUQk1vvSXhMFxozW3kWx9JZojIW2aEYJXNox4B7fYiIcp1nusmLv t1D_c_FJF1i9vioN8_0eATsJ.LX84MRfe1KsbP4M5EGlgsfzyzMJJMdSTyKN Mw861dN8KHR6.bD4ZwmcJNEXWxsOaz0ZpGv6hvE0ZdI53Ig744iwyNRg_LeD G9VHRzPkOtCj3ogE3i48gHCIWrsYcAFbLDnNKGB9lUsWsHxxVXTdsi.7kWAI 2yemA3P9gwqiTIUM648Vq X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp106.prem.mail.sp1.yahoo.com with SMTP; 26 Jan 2012 16:20:13 -0800 PST From: "David Johnston" To: "'Carlos Mennens'" , "'PostgreSQL \(SQL\)'" References: In-Reply-To: Subject: Re: Update Mass Data in Field? Date: Thu, 26 Jan 2012 19:20:07 -0500 Message-ID: <003d01ccdc89$6ce132f0$46a398d0$@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: AQGeA09Cd9JaQl9cWgo32aqUbbx7N5Z9CuNw Content-Language: en-us X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/106 X-Sequence-Number: 36277 -----Original Message----- From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Carlos Mennens Sent: Thursday, January 26, 2012 6:59 PM To: PostgreSQL (SQL) Subject: [SQL] Update Mass Data in Field? I'm new to SQL so I'm looking for a way to change several email addresses with one command. For example everyone has a 'holyghost.org' domain and I need to change a few 100 email addresses in the field 'emp_email'. I need to UPDATE employees table which has a COLUMN 'emp_email' and change %holyghost.org to %ghostsoftware.com. I tried: UPDATE employees SET emp_email = '%ghostsoftware.com' WHERE emp_email LIKE '%holyghost.org'; It didn't update anything when I ran the command. Does anyone know how I need to correct my SQL statement above to change everyone's email address? ------------------------------------------------ Like Steve said, use the "regexp_replace" function. However, I am concerned that nothing updated when you executed the above. What you should have seen happen is that EVERY email address ending with "holyghost.org" became changed to the literal value "%ghostsoftware.com" - which obviously is not an e-mail address - and the original "holyghost.org" email address would have been gone beyond easy recovery. Takeaway: test update queries on sample data (or at least within a transaction block) and confirm your results before executing against live data (or committing the transaction). David J.