Show / Hide Table of Contents

Class NpgsqlBinaryImporter

Provides an API for a binary COPY FROM operation, a high-performance data import mechanism to a PostgreSQL table. Initiated by BeginBinaryImport(String)

Inheritance
System.Object
NpgsqlBinaryImporter
Implements
System.IDisposable
IAsyncDisposable
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Npgsql
Assembly: Npgsql.dll
Syntax
public sealed class NpgsqlBinaryImporter : ICancelable, IDisposable, IAsyncDisposable
Remarks

See http://www.postgresql.org/docs/current/static/sql-copy.html.

Methods

Close()

Completes the import process and signals to the database to write everything.

Declaration
public void Close()

CloseAsync(CancellationToken)

Async completes the import process and signals to the database to write everything.

Declaration
public ValueTask CloseAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
Returns
Type Description
ValueTask
Exceptions
Type Condition
System.Exception

Complete()

Completes the import operation. The writer is unusable after this operation.

Declaration
public void Complete()

CompleteAsync(CancellationToken)

Completes the import operation. The writer is unusable after this operation.

Declaration
public ValueTask<ulong> CompleteAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
Returns
Type Description
ValueTask<System.UInt64>

Dispose()

Cancels that binary import and sets the connection back to idle state

Declaration
public void Dispose()

DisposeAsync()

Async cancels that binary import and sets the connection back to idle state

Declaration
public ValueTask DisposeAsync()
Returns
Type Description
ValueTask

StartRow()

Starts writing a single row, must be invoked before writing any columns.

Declaration
public void StartRow()

StartRowAsync(CancellationToken)

Starts writing a single row, must be invoked before writing any columns.

Declaration
public Task StartRowAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task

Write<T>(T)

Writes a single column in the current row.

Declaration
public void Write<T>(T value)
Parameters
Type Name Description
T value

The value to be written

Type Parameters
Name Description
T

The type of the column to be written. This must correspond to the actual type or data corruption will occur. If in doubt, use Write<T>(T, NpgsqlDbType) to manually specify the type.

Write<T>(T, NpgsqlDbType)

Writes a single column in the current row as type npgsqlDbType.

Declaration
public void Write<T>(T value, NpgsqlDbType npgsqlDbType)
Parameters
Type Name Description
T value

The value to be written

NpgsqlDbType npgsqlDbType

In some cases T isn't enough to infer the data type to be written to the database. This parameter and be used to unambiguously specify the type. An example is the JSONB type, for which T will be a simple string but for which npgsqlDbType must be specified as Jsonb.

Type Parameters
Name Description
T

The .NET type of the column to be written.

Write<T>(T, String)

Writes a single column in the current row as type dataTypeName.

Declaration
public void Write<T>(T value, string dataTypeName)
Parameters
Type Name Description
T value

The value to be written

System.String dataTypeName

In some cases T isn't enough to infer the data type to be written to the database. This parameter and be used to unambiguously specify the type.

Type Parameters
Name Description
T

The .NET type of the column to be written.

WriteAsync<T>(T, NpgsqlDbType, CancellationToken)

Writes a single column in the current row as type npgsqlDbType.

Declaration
public Task WriteAsync<T>(T value, NpgsqlDbType npgsqlDbType, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
T value

The value to be written

NpgsqlDbType npgsqlDbType

In some cases T isn't enough to infer the data type to be written to the database. This parameter and be used to unambiguously specify the type. An example is the JSONB type, for which T will be a simple string but for which npgsqlDbType must be specified as Jsonb.

System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task
Type Parameters
Name Description
T

The .NET type of the column to be written.

WriteAsync<T>(T, String, CancellationToken)

Writes a single column in the current row as type dataTypeName.

Declaration
public Task WriteAsync<T>(T value, string dataTypeName, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
T value

The value to be written

System.String dataTypeName

In some cases T isn't enough to infer the data type to be written to the database. This parameter and be used to unambiguously specify the type.

System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task
Type Parameters
Name Description
T

The .NET type of the column to be written.

WriteAsync<T>(T, CancellationToken)

Writes a single column in the current row.

Declaration
public Task WriteAsync<T>(T value, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
T value

The value to be written

System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task
Type Parameters
Name Description
T

The type of the column to be written. This must correspond to the actual type or data corruption will occur. If in doubt, use Write<T>(T, NpgsqlDbType) to manually specify the type.

WriteNull()

Writes a single null column value.

Declaration
public void WriteNull()

WriteNullAsync(CancellationToken)

Writes a single null column value.

Declaration
public Task WriteNullAsync(CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task

WriteRow(Object[])

Writes an entire row of columns. Equivalent to calling StartRow(), followed by multiple Write<T>(T) on each value.

Declaration
public void WriteRow(params object[] values)
Parameters
Type Name Description
System.Object[] values

An array of column values to be written as a single row

WriteRowAsync(CancellationToken, Object[])

Writes an entire row of columns. Equivalent to calling StartRow(), followed by multiple Write<T>(T) on each value.

Declaration
public Task WriteRowAsync(CancellationToken cancellationToken = default(CancellationToken), params object[] values)
Parameters
Type Name Description
System.Threading.CancellationToken cancellationToken
System.Object[] values

An array of column values to be written as a single row

Returns
Type Description
System.Threading.Tasks.Task

Implements

System.IDisposable
IAsyncDisposable
In This Article
Back to top Generated by DocFX