X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 30475D1CCA5 for ; Fri, 19 Dec 2003 18:33:58 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 50619-08 for ; Fri, 19 Dec 2003 14:33:09 -0400 (AST) Received: from hotmail.com (bay9-f58.bay9.hotmail.com [64.4.47.58]) by svr1.postgresql.org (Postfix) with ESMTP id 9BEBBD1B4A7 for ; Fri, 19 Dec 2003 14:29:08 -0400 (AST) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Fri, 19 Dec 2003 10:29:08 -0800 Received: from 65.205.28.100 by by9fd.bay9.hotmail.msn.com with HTTP; Fri, 19 Dec 2003 18:29:08 GMT X-Originating-IP: [65.205.28.100] X-Originating-Email: [nutter_@hotmail.com] X-Sender: nutter_@hotmail.com From: "Matt Van Mater" To: guy@incentre.net Cc: pgsql-sql@postgresql.org Subject: Re: how to preserve \n in select statement Date: Fri, 19 Dec 2003 13:29:08 -0500 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 19 Dec 2003 18:29:08.0784 (UTC) FILETIME=[FDBDD300:01C3C65D] X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200312/133 X-Sequence-Number: 16299 I have been entering the data by having a command file that inserts the rows one by one. (yes I know a copy command would probably be faster for importing bulk data, but I prefer to insert each line individually) IE: psql -U myusername mydatabase -f '/path/to/commandfile' Inside the commandfile I have lines like: INSERT INTO tablename (col1, col2, col3) VALUES ($val1, $val2, $val3); How do I escape the data from a select statement? Something like: SELECT \* FROM tablename; ? ----Original Message Follows---- From: Guy Fraser To: Matt Van Mater Subject: Re: [SQL] how to preserve \n in select statement Date: Fri, 19 Dec 2003 08:43:59 -0700 What are you using to enter and retrieve the data? Either escape the data before you put it in the database or when you retieve it, whichever gives you the results you are looking for. Matt Van Mater wrote: >I have a table that has a few text value types, and I enter a bunch of text >with '\n' representing a newline. When I select the records from that >table, postgresql 7.3 represents those \n as newlines and actually outputs >the a newline rather than as a \n as entered. I want to be able to get my >\n text out of the select statement in the exact same manner it was >inserted. > >I found a workaround where I can use the copy to command to copy a table to >a text file, and the command preserves the \n characters. The problem with >that is the copy to command overwrites the output file every time it is >written to. That stinks because then I can't run multiple queries and >direct the output to a file all at once. (I would prefer to set the output >file as \o '/path/to/oufile.txt' and have all queries dump their results >there) > >Is there a way to make the select statement not interpret newline escape >characters? > >Matt Van Mater _________________________________________________________________ Check your PC for viruses with the FREE McAfee online computer scan. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963