# How to put File lines into postgres query(pg)

**URL:** <https://www.ruby-forum.com/t/how-to-put-file-lines-into-postgres-query-pg/180485>\
**Category:** Ruby\
**Created:** [December 19, 2009, 10:05pm UTC](https://www.ruby-forum.com/t/how-to-put-file-lines-into-postgres-query-pg/180485 "2009-12-19T22:05:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![beny18241](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbce88/32.png) [@beny18241](https://www.ruby-forum.com/u/beny18241)\
**Post date:** [December 19, 2009, 10:05pm UTC](https://www.ruby-forum.com/t/how-to-put-file-lines-into-postgres-query-pg/180485/1 "2009-12-19T22:05:40Z")

</div>

Hi,

I have a script which parsing some xml files(works great :))

* * *

## File.open(file).each do |line| if line =~ /prf:CcppAccept/…line =~ /\</prf:CcppAccept\>/ if line =~ /rdf:li(image|audio|video).\*\</rdf:li\>/ line.gsub( ‘rdf:liimage/bmp’, “INSERT INTO table VALUES(’#{dev\_name}’,‘bmpinpage’,‘true’)”).gsub( ‘rdf:liaudio/mp3’, “INSERT INTO table VALUES(’#{dev\_name}’,‘downloadable.audio.MP3’)”).gsub( ‘rdf:livideo/mp4’,“INSERT INTO table VALUES(’#{dev\_name}’,‘downloadable.video.MP4’)”).gsub( “\</rdf:li\>”, “;”).each do |ss| print ss end end end end

but now I wanted to put this regexped lines into postgres queries

def query1  
conn =  
PGconn.new({:host=\>‘localhost’,:user=\>‘postgres’,:dbname=\>‘data’})  
res = conn.exec(’#{ss}’)  
res.each do |row|  
row.each do |column|  
print column  
end  
puts  
end

but its not working, please can anybody tell how to push this lines into  
this postgres querries ??

Regards  
beny18241
