Sha256: 4d6b26088b1658b8a9d74dae49d6de19f505d1977f72ea92ebad277c564302a8

Contents?: true

Size: 583 Bytes

Versions: 1

Compression:

Stored size: 583 Bytes

Contents

#!/usr/bin/env ruby

require 'pg'
require 'stringio'

# An example of how to stream data to your local host from the database as CSV.

$stderr.puts "Opening database connection ..."
conn = PGconn.connect( :dbname => 'test' )

### You can test the error case from the database side easily by
### changing one of the numbers at the end of one of the above rows to
### something non-numeric like "-".

$stderr.puts "Running COPY command ..."
buf = ''
conn.transaction do
	conn.exec( "COPY logs TO STDOUT WITH csv" )
	$stdout.puts( buf ) while buf = conn.get_copy_data
end

conn.finish

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pg-0.12.0pre258 sample/copyto.rb