Sha256: 044c35be95786ab7766e2a894b92f044adffc15e9454931d7ed07ed613f4c361

Contents?: true

Size: 828 Bytes

Versions: 123

Compression:

Stored size: 828 Bytes

Contents

# -*- ruby -*-

require 'pg'
require 'stringio'

# Using COPY asynchronously

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

socket = conn.socket_io

$stderr.puts "Running COPY command ..."
buf = ''
conn.transaction do
	conn.send_query( "COPY logs TO STDOUT WITH csv" )
	buf = nil

	# #get_copy_data returns a row if there's a whole one to return, false
	# if there isn't one but the COPY is still running, or nil when it's
	# finished.
	begin
		$stderr.puts "COPY loop"
		conn.consume_input
		while conn.is_busy
			$stderr.puts "  ready loop"
			select( [socket], nil, nil, 5.0 ) or
				raise "Timeout (5s) waiting for query response."
			conn.consume_input
		end

		buf = conn.get_copy_data
		$stdout.puts( buf ) if buf
	end until buf.nil?
end

conn.finish

Version data entries

123 entries across 123 versions & 4 rubygems

Version Path
pg-1.5.6 sample/async_copyto.rb
pg-1.5.5-x86-mingw32 sample/async_copyto.rb
pg-1.5.5-x64-mingw32 sample/async_copyto.rb
pg-1.5.5-x64-mingw-ucrt sample/async_copyto.rb
pg-1.5.5 sample/async_copyto.rb
pg-1.5.4-x86-mingw32 sample/async_copyto.rb
pg-1.5.4-x64-mingw32 sample/async_copyto.rb
pg-1.5.4-x64-mingw-ucrt sample/async_copyto.rb
pg-1.5.4 sample/async_copyto.rb
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/sample/async_copyto.rb
pg-1.5.3-x64-mingw32 sample/async_copyto.rb
pg-1.5.3-x64-mingw-ucrt sample/async_copyto.rb
pg-1.5.3-x86-mingw32 sample/async_copyto.rb
pg-1.5.3 sample/async_copyto.rb
pg-1.5.2-x64-mingw32 sample/async_copyto.rb
pg-1.5.2-x64-mingw-ucrt sample/async_copyto.rb
pg-1.5.2 sample/async_copyto.rb
pg-1.5.1-x86-mingw32 sample/async_copyto.rb
pg-1.5.1-x64-mingw-ucrt sample/async_copyto.rb
pg-1.5.1-x64-mingw32 sample/async_copyto.rb