# Unable run \\copy command via PGconn.( exec || query )

**URL:** <https://www.ruby-forum.com/t/unable-run-copy-command-via-pgconn-exec-query/164646>\
**Category:** Ruby\
**Created:** [April 3, 2009, 5:10pm UTC](https://www.ruby-forum.com/t/unable-run-copy-command-via-pgconn-exec-query/164646 "2009-04-03T17:10:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashikalim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@ashikalim](https://www.ruby-forum.com/u/ashikalim)\
**Post date:** [April 3, 2009, 5:10pm UTC](https://www.ruby-forum.com/t/unable-run-copy-command-via-pgconn-exec-query/164646/1 "2009-04-03T17:10:18Z")

</div>

Hi ,  
I am facing problem while executing following code :

require ‘postgres’  
obj = PGconn.new( ‘192.168.1.156’,5432 ,’’,’’,‘tikono’,‘tikono’,‘tikono’  
)  
a = “\COPY  
ivr\_interface.call\_flow(ref\_id,loaded\_time,menuid,expected\_dtmf,expected\_dtmf\_status,processing\_input,confirmation,external\_staus,external\_value)  
from ./backupFiles/ivr\_interface.call\_flow.new WITH DELIMITER ‘$’ NULL  
‘nil’”  
p a  
obj.exec( a )  
p obj.methods

Error :  
query.rb:5:in `exec’: ERROR: syntax error at or near “” at character 1  
(PGError)  
from query.rb:5  
X=============================X

If I use “\copy …” , Instead of “\copy” then I got  
query.rb:3: Invalid escape character syntax  
a = “\COPY  
ivr\_interface.call\_flow(ref\_id,loaded\_time,menuid,expected\_dtmf,expected\_dtmf\_status,processing\_input,confirmation,external\_staus,external\_value)  
from ./backupFiles/ivr\_interface.call\_flow.new WITH DELIMITER ‘$’ NULL  
‘nil’”

Note : Not PGERROR

If I use ,  
‘\COPY  
ivr\_interface.call\_flow(ref\_id,loaded\_time,menuid,expected\_dtmf,expected\_dtmf\_status,processing\_input,confirmation,external\_staus,external\_value)  
from ./backupFiles/ivr\_interface.call\_flow.new WITH DELIMITER ‘$’  
NULL ‘nil’’

I got the Error as ,  
query.rb:5:in `exec’: ERROR: syntax error at or near “” at character 1  
(PGError)  
from query.rb:5

Can anyone tell me How to escape this \copy in PGconn.( query|| exec )  
method ?

cheers,  
ashikali

---

<div class="post-metadata">

**Author:** ![ashikalim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@ashikalim](https://www.ruby-forum.com/u/ashikalim)\
**Post date:** [April 3, 2009, 5:21pm UTC](https://www.ruby-forum.com/t/unable-run-copy-command-via-pgconn-exec-query/164646/2 "2009-04-03T17:21:25Z")

</div>

On Apr 3, 2009, at 9:09 AM, Ashikali A. wrote:

> Can anyone tell me How to escape this \copy in PGconn.( query|| exec )

all of the \*\*\* commands are implemented by the psql command line  
program, not the database, so none of them will ever work with a raw  
connection. fyi.

a @ [http://codeforpeople.com/](http://codeforpeople.com/)

---

<div class="post-metadata">

**Author:** ![ashikalim](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@ashikalim](https://www.ruby-forum.com/u/ashikalim)\
**Post date:** [April 3, 2009, 6:17pm UTC](https://www.ruby-forum.com/t/unable-run-copy-command-via-pgconn-exec-query/164646/3 "2009-04-03T18:17:43Z")

</div>

Ara Howard wrote:

> On Apr 3, 2009, at 9:09 AM, Ashikali A. wrote:
> 
> > Can anyone tell me How to escape this \copy in PGconn.( query|| exec )
> 
> all of the \*\*\* commands are implemented by the psql command line  
> program, not the database, so none of them will ever work with a raw  
> connection. fyi.
> 
> a @ [http://codeforpeople.com/](http://codeforpeople.com/)

Thanks for your response . But I found the solution using psql command .  
That is ,  
psql -A -c “\COPY  
ivr\_interface.call\_reports(pbxid,channeltype,callerid,calledid,landedtime,endedtime,endstatus,endreason,progresslangauge,defaultlanguage,internalerror)  
from ./backupFiles/ivr\_interface.call\_reports.new WITH DELIMITER ‘$’  
NULL ‘nil’” -q -t -h 192.168.1.156 -U tikono tikono"

cheers,  
ashikali
