Unix Technical Forum

copy with escape

This is a discussion on copy with escape within the Pgsql General forums, part of the PostgreSQL category; --> I have data that I'm running through pg_escape_sting in php and then adding to stdin for a copy command. ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 12:20 AM
blackwater dev
 
Posts: n/a
Default copy with escape

I have data that I'm running through pg_escape_sting in php and then adding
to stdin for a copy command. The problem is "O'reilly" is being changed to
"O''Reilly" in the string and then in the db. I saw with the copy command I
can specify the escape but it isn't working for me. Should this command fix
this double 'single' quote issue when I put it in the db? And what is the
proper syntax?

COPY mytable FROM stdin with escape



Thanks!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 12:20 AM
Tom Lane
 
Posts: n/a
Default Re: copy with escape

"blackwater dev" <blackwaterdev@gmail.com> writes:
> I have data that I'm running through pg_escape_sting in php and then adding
> to stdin for a copy command. The problem is "O'reilly" is being changed to
> "O''Reilly" in the string and then in the db.


pg_escape_string is designed to produce a string properly quoted for use
as a literal in a SQL command. It is completely wrong for data that is
to go into COPY input. I kinda doubt that PHP has anything built-in
that's suitable for COPY, though I could be wrong ...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 12:20 AM
brian
 
Posts: n/a
Default Re: copy with escape



blackwater dev wrote:
> I have data that I'm running through pg_escape_sting in php and then adding
> to stdin for a copy command. The problem is "O'reilly" is being changed to
> "O''Reilly" in the string and then in the db. I saw with the copy command I
> can specify the escape but it isn't working for me. Should this command fix
> this double 'single' quote issue when I put it in the db? And what is the
> proper syntax?
>
> COPY mytable FROM stdin with escape
>
>



COPY mytable (...) FROM STDIN WITH CSV ESCAPE "'";

http://www.postgresql.org/docs/8.3/static/sql-copy.html

But CSV comes with a lot of baggage. You'd be far better off doing
tab-delimited, unquoted fields (if you have no tabs in your data).

COPY mytable (...) FROM STDIN;
....
\.

I can't remember precisely all of what pg_escape_string() does, but if
you need it for something else you could always do this afterward ;-)

implode("\t", str_replace("''", "'", $row))

b

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:15 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com