Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

New line character in varchar field

182 views
Skip to first unread message

Candy Lam

unread,
Jul 20, 1999, 3:00:00 AM7/20/99
to info-...@ams.org
I'd wonder if anybody had this problem before.  I'm attempt to upload an address file into a varchar field in a table.  The data itself consists of new line and carriage return character.

I know that in isql one can add one address by changing the string to :
    'string' + X'0A' + X'0D'
However, when I tried to upload a file to table, it takes the characters literally.

Can anybody offer any hint?

Steve McDaniel

unread,
Jul 20, 1999, 3:00:00 AM7/20/99
to Candy Lam, info-...@ams.org
I'm not clear on your question.

Are you asking how to remove embedded newlines and carriage returns?

If so, if this is a Unix system, I'd suggest using 'sed' or something like
that to remove the newlines/carriage returns before loading into the database.

Steve


At 10:57 AM 7/20/99 +0100, Candy Lam wrote:
>
>--Boundary_(ID_dsyvOetZ6madXeIlOJg1Bg)
>Content-type: text/plain; charset=us-ascii
>Content-transfer-encoding: 7bit

>--Boundary_(ID_dsyvOetZ6madXeIlOJg1Bg)
>Content-type: text/html; charset=us-ascii
>Content-transfer-encoding: 7bit
>
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
><HTML>
>I'd wonder if anybody had this problem before.&nbsp; I'm attempt to upload
>an address file into a varchar field in a table.&nbsp; The data itself


>consists of new line and carriage return character.

><P>I know that in isql one can add <B>one</B> address by changing the string
>to :
><BR>&nbsp;&nbsp;&nbsp; 'string' + X'0A' + X'0D'
><BR>However, when I tried to upload a file to table, it takes the characters
>literally.
><P>Can anybody offer any hint?</HTML>
>
>--Boundary_(ID_dsyvOetZ6madXeIlOJg1Bg)--
>

+--------------------------------------------------------------------------+
| Steve McDaniel | |
| Corporate Database Manager | E-Mail: Steve.M...@cmdg.com |
| CMD Group | Voice: (770) 417-4201 |
| 30 Technology Parkway South | Fax: (770) 797-2010 |
| Suite 100 | Cell: (770) 331-1587 |
| Norcross, GA 30092 | |
+--------------------------------------------------------------------------+
____________________________________________________________________________
Notice: This message contains privileged and confidential information
intended only for the use of the addressee named above. If you are not
the intended recipient of this message, you are hereby notified that
you should not disseminate, copy or take any action in reliance on it.
If you have received this message in error please notify the CMD Group
in Atlanta, Georgia, USA on (770) 417-4000.

Martin Bowes

unread,
Jul 20, 1999, 3:00:00 AM7/20/99
to Candy Lam
Hi Candy,

Hope this helps...

The critical thing here is to have a good delimiter for the end of the
address field. ie as you're already using newlines and may allow tabs in an
address. If the input file doesnt have them that'll make life a lot harder
and you may have to resort to a file processing script for awk or Perl to
help.

As an example, consider a file of names and addresses like:

a frog<TAB>13 the lilly pad
in the swamp
by the tree
*
a drover<TAB>bury me deep down below
where the dingoes and crows cant molest me
in the land where good drovers go
*
...End of File...
Note that we have two fields. A name field delimited by a tab character and an
address field spread over several lines delimited by an '*'. Each row is
terminated with a newline.

This can be loaded into a simple table with:
copy table address_test(
name=c0tab,
address='c0*',
dummy=d0nl
) from 'dummy.dat'

The result being:

Executing . . .


select * from address_test

+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|name |address |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|a frog |13 the lilly pad\nin the swamp\nby the tree\n |
|a drover |bury me deep down below\nwhere the dingoes and crows cant molest me\nin the land where good drovers go\n |
+------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
(2 rows)
continue
Your SQL statement(s) have been committed.

Best of luck,

Martin Bowes


--
Random Duckman Quote #4:
Cornfed - You're aware that while it affords one the momentary
illusion of satisfaction, the spewing of bile is
never a permanent solution.

Candy Lam

unread,
Jul 21, 1999, 3:00:00 AM7/21/99
to info-...@ams.org
Thanks a lot guys!  I've solved the problem now and happy again.
0 new messages