Received: from mail.enterprise.net (mail.enterprise.net [194.72.192.18]) by hub.org (8.10.1/8.10.1) with ESMTP id e5N60w101946 for ; Fri, 23 Jun 2000 02:00:58 -0400 (EDT) Received: from linda.lfix.co.uk (cmax05-075.enterprise.net [212.161.115.75]) by mail.enterprise.net (8.8.5/8.8.5) with ESMTP id HAA07962; Fri, 23 Jun 2000 07:00:55 +0100 (GMT/BST) Received: from lfix.co.uk (olly@localhost [127.0.0.1]) by linda.lfix.co.uk (8.11.0.Beta1/8.11.0.Beta1/Debian 8.11.0-1) with ESMTP id e5N5rde14918; Fri, 23 Jun 2000 06:53:57 +0100 Message-Id: <200006230553.e5N5rde14918@linda.lfix.co.uk> X-Authentication-Warning: linda.lfix.co.uk: Host olly@localhost [127.0.0.1] claimed to be lfix.co.uk X-Mailer: exmh version 2.1.1 10/15/1999 (debian) To: Christopher Sawtell cc: "Gary MacMinn" , pgsql-sql@postgresql.org Subject: Re: Merging two columns into one In-Reply-To: Message from Christopher Sawtell of "Fri, 23 Jun 2000 17:10:38 +1200." <00062317123201.15938@berty> References: <00062317123201.15938@berty> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 23 Jun 2000 06:53:37 +0100 From: "Oliver Elphick" X-Archive-Number: 200006/202 Christopher Sawtell wrote: >On Fri, 23 Jun 2000, Gary MacMinn wrote: >> Hi All, >> >> I have two columns in a table (areacode and phone number) that I'd like to > merge >into one (phone number) containing both sets of info. Could anyone suggest a >simple way of achieving this? > >export the data to a file using the copy command, >remove the delimiter with the unix command 'tr -d' >import the file, now minus the delimeter using the copy command. Surely tr will remove ALL the delimiters, so this is not helpful unless these columns are the only ones in the table. You would have to use awk or perl to process the exported file and delete the correct delimiter. For an SQL solution, how about: SELECT col1, col2,..., areacode || phone as phone, colx, coly,... INTO new_table FROM table; Then you can drop the old table and recreate it with the correct columns and import the data into it from new_table. (You could just rename new_table if it doesn't need to be created with constraints.) -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight http://www.lfix.co.uk/oliver PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47 GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "Train up a child in the way he should go, and when he is old, he will not depart from it." Proverbs 22:6