# Postgres text field returns wrong data

**URL:** <https://www.ruby-forum.com/t/postgres-text-field-returns-wrong-data/143253>\
**Category:** Rails\
**Created:** [July 16, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/postgres-text-field-returns-wrong-data/143253 "2008-07-16T20:13:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [July 16, 2008, 8:13pm UTC](https://www.ruby-forum.com/t/postgres-text-field-returns-wrong-data/143253/1 "2008-07-16T20:13:32Z")

</div>

I am having an interesting problem. I have a Postgres database with a  
table containing a text field. In the text field is stored data that in  
some cases has a ‘\*’ and a newline return as the first line first few  
characters followed by several other lines.

The strange part is when a record is written the data looks correct,  
however, when the record is read all line feed and carriage returns are  
stripped in the response data.

I am using the GEM postgres-pr driver 0.4.0 on rails 2.0.2

Is there any reason this would occur? If I have other records without  
the ‘\*’ as described above the data read is correct (all new lines and  
returns remain).

Sample Text data written as a string, when read no line feeds or  
carriage returns:  
\*

- THIS JOB SEND A FILE
- 

[ADMIN]  
VERSION = 1  
DESC = job 1  
USERID = admin

Any help is appreciated. I wouldn’t mind digging through the driver to  
debug this issue, however I’m not sure where to start. Any guidance or  
comments are appreciated.

Rick

---

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [July 17, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/postgres-text-field-returns-wrong-data/143253/2 "2008-07-17T16:17:45Z")

</div>

Rick F. wrote:

> I am having an interesting problem. I have a Postgres database with a  
> table containing a text field. In the text field is stored data that in  
> some cases has a ‘\*’ and a newline return as the first line first few  
> characters followed by several other lines.
> 
> The strange part is when a record is written the data looks correct,  
> however, when the record is read all line feed and carriage returns are  
> stripped in the response data.
> 
> I am using the GEM postgres-pr driver 0.4.0 on rails 2.0.2

Just to isolate the problem, could you try using the binary postgres  
driver? If you’re on Windows you could try using a precompiled driver  
from [http://www.vandomburg.net](http://www.vandomburg.net).

–  
Roderick van Domburg

> **[De domeinnaam Nedforce.nl is te koop.](http://www.nedforce.nl)**
>
> Deze mooie domeinnaam kan al over een paar minuten van jou zijn. Betalen gaat eenvoudig en vertrouwd via iDEAL. Direct na de betaling ontvang je de verhuiscode per e-mail en kun je aan de slag.

---

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [July 17, 2008, 4:42pm UTC](https://www.ruby-forum.com/t/postgres-text-field-returns-wrong-data/143253/3 "2008-07-17T16:42:36Z")

</div>

Hi Roderick,

I will do what you suggest when I get a moment. Here is what I have  
found so far:

In the ActiveRecord-2.0.2 gem file ‘base.rb’ the ‘find\_every(options)’  
method returns the data (records) correctly formatted (all the new lines  
in tact). Somewhere after this call the data as described above is  
stripped of the line feeds and carriage returns due to the ‘\*’.

I am adding in some tracing so I can determine the code flow and isolate  
where the sanitizing or whatever takes place.

Thanks for you response, I’ll let you know regarding the binary driver.

Thanks,  
Rick
