On Sep 16, 2:22 pm, Joe Van Dyk <[email protected]> wrote:
> On Sep 16, 1:57 pm, Michael Granger <[email protected]> wrote:
> > With the 'pg' library you can read from a COPY like so:
>
> > conn.exec( "COPY logs TO STDOUT WITH csv" )
> > $stdout.puts( buf ) while buf = conn.get_copy_data
>
> > I'll be adding an example of this under the samples/ directory of the
> > gem shortly.
>
> That's pretty awesome! Thanks.
Note that you can still use Sequel in general and drop down to pg just
for that code:
DB.synchronize do |conn|
conn.exec( "COPY logs TO STDOUT WITH csv" )
$stdout.puts( buf ) while buf = conn.get_copy_data
end
This could probably be made easier with Sequel:
def get_copy_data(table)
DB.synchronize do |conn|
conn.exec( "COPY logs TO STDOUT WITH csv" )
while buf = conn.get_copy_data
yield buf
end
end
end
However, I'm not sure what happens to the connection if you don't get
all of the data. If it could be made safe using an ensure block to
ensure the connection is left in a good state, I don't have any
problem adding this to Sequel.
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.