Copy is an efficient (typically tens of times faster than
INSERT) bulk data exchange method
for PostgreSQL databases. This is
a driver extension to support
COPY FROM STDIN and
COPY TO STDOUT data exchange with the client for PostgresSQL dot-Net driver Npgsql.
Derived from my
earlier implementation for JDBC, it provides a simple
Stream based API while keeping low level protocol handling in the
internal class meant for that purpose.
The original patch was made against latest published beta and is already included in Npgsql2 CVS. Fixes in the other patch are not yet; it's against CVS HEAD for now. So please use the DLL with latest time stamp, apply both patches against latest beta source or apply latest patch against source from CVS HEAD.
Full original source without the patches is available at the official site: http://pgfoundry.org/projects/npgsql
Readily usable DLL compiled with nant on OSX is also available.
gacutil -i Npgsql.dll
Constructor takes a SQL command, database connection and optional readable stream. Given command is executed upon Start() and all data from fromStream is passed to it as copy data. If fromStream is not provided, CopyStream is set to provide a writable stream. Data for the requested COPY IN operation can then be written to CopyData stream followed by a call to End() (also issued if the writable stream is closed) to complete or Cancel() to withdraw the operation.
NpgsqlCopyIn(NpgsqlCommand cmd, NpgsqlConnection conn, Stream fromStream)
NpgsqlCopyIn(NpgsqlCommand cmd, NpgsqlConnection conn)
NpgsqlCopyIn(string copyInQuery, NpgsqlConnection conn)
Constructor takes a SQL command, database connection and optional writable stream. Given command is executed upon Start() and all data from it is passed to toStream. If toStream is not provided, CopyStream is set to provide a readable stream. Data from the requested COPY OUT operation can then be read from CopyData stream until a null record (from byte Read()) or zero bytes (from int Read(byte,int,int). End() should be called to clean up afterwards. Closing provided readable CopyStream discards rest of copy data from server.
NpgsqlCopyOut(NpgsqlCommand cmd, NpgsqlConnection conn, Stream toStream)
NpgsqlCopyOut(NpgsqlCommand cmd, NpgsqlConnection conn)
NpgsqlCopyOut(string copyOutQuery, NpgsqlConnection conn)
pgcopy "CREATE TEMP TABLE t(t text)" "COPY t FROM STDIN" -o out "COPY t TO STDOUT"