Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 22nd, 2005, 08:50 AM
C G
Guest
 
Posts: n/a
Default Copy and xml files

Dear All,

I'm trying to insert an xml file into my database. I have a table with a
single text column. My intention is just to have the xml file take up one
row in the table.

I've tried the command

COPY t1 FROM '/tmp/file.xml';

but keep getting the error message

ERROR: extra data after last expected column
CONTEXT: COPY t1, line 32: " <cn type="integer"> 1 </cn>"

Thanks for any help

Colin

__________________________________________________ _______________
Sign-up for a FREE BT Broadband connection today!
http://www.msn.co.uk/specials/btbroadband


---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend




  #2  
Old November 22nd, 2005, 08:50 AM
Chris Gamache
Guest
 
Posts: n/a
Default Re: Copy and xml files

COPY works for whole tables, and can't append rows. You're going to have to
escape your linebreaks and tabs to use COPY ... As I recall, you can specify
your own custom column and row delimiters... You might consider creating some
type of primary key for the table. A "serial" column would work fine.

If you want to insert a single row into a table, you'll need to do it with an
insert statement. something like :

# psql your_database -c "insert into t1 (xml_column) values ('`cat
/tmp/file.xml | sed -e \"s/'/''/g\"`');"


HTH,

CG

--- C G <csgcsg39@hotmail.com> wrote:[color=blue]
> Dear All,
>
> I'm trying to insert an xml file into my database. I have a table with a
> single text column. My intention is just to have the xml file take up one
> row in the table.
>
> I've tried the command
>
> COPY t1 FROM '/tmp/file.xml';
>
> but keep getting the error message
>
> ERROR: extra data after last expected column
> CONTEXT: COPY t1, line 32: " <cn type="integer"> 1 </cn>"
>
> Thanks for any help
>
> Colin
>
> __________________________________________________ _______________
> Sign-up for a FREE BT Broadband connection today!
> http://www.msn.co.uk/specials/btbroadband
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend[/color]


__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free web site building tool. Try it!
http://webhosting.yahoo.com/ps/sb/

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

  #3  
Old November 22nd, 2005, 08:51 AM
Guy Fraser
Guest
 
Posts: n/a
Default Re: Copy and xml files

Chris Gamache wrote:
[color=blue]
>COPY works for whole tables, and can't append rows. ...
>
>[/color]
Wrong!

I use copy regularly to add data to a table.


....snip...
[color=blue]
>--- C G <csgcsg39@hotmail.com> wrote:
>
>[color=green]
>>Dear All,
>>
>>I'm trying to insert an xml file into my database. I have a table with a
>>single text column. My intention is just to have the xml file take up one
>>row in the table.
>>
>>I've tried the command
>>
>>COPY t1 FROM '/tmp/file.xml';
>>
>>but keep getting the error message
>>
>>ERROR: extra data after last expected column
>>CONTEXT: COPY t1, line 32: " <cn type="integer"> 1 </cn>"
>>
>>Thanks for any help
>>
>>Colin
>>
>>[/color][/color]
If you are trying to import the whole file into one 'column' of a table, you will need to escape the "end of line" [carriage return/line feed] characters.

I believe this question has been asked many times, and the method of importing this type of data is in the archives.

Please check the archives.





---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,414 network members.