Search Results for

    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
    object
    NpgsqlBinaryImporter
    Implements
    IDisposable
    IAsyncDisposable
    Namespace: Npgsql
    Assembly: Npgsql.dll
    Syntax
    public sealed class NpgsqlBinaryImporter : IDisposable, IAsyncDisposable
    Remarks

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

    Properties

    | Improve this Doc View Source

    Timeout

    Current timeout

    Declaration
    public TimeSpan Timeout { set; }
    Property Value
    Type Description
    TimeSpan
    Remarks

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

    Methods

    | Improve this Doc View Source

    Close()

    Terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.

    Note that if Complete() hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.

    Declaration
    public void Close()
    Remarks

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

    | Improve this Doc View Source

    CloseAsync(CancellationToken)

    Async terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.

    Note that if CompleteAsync(CancellationToken) hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.

    Declaration
    public ValueTask CloseAsync(CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    CancellationToken cancellationToken
    Returns
    Type Description
    ValueTask
    Remarks

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

    | Improve this Doc View Source

    Complete()

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

    Declaration
    public ulong Complete()
    Returns
    Type Description
    ulong
    Remarks

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

    | Improve this Doc View Source

    CompleteAsync(CancellationToken)

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

    Declaration
    public ValueTask<ulong> CompleteAsync(CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    CancellationToken cancellationToken
    Returns
    Type Description
    ValueTask<><ulong>
    Remarks

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

    | Improve this Doc View Source

    Dispose()

    Terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.

    Note that if Complete() hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.

    Declaration
    public void Dispose()
    Remarks

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

    | Improve this Doc View Source

    DisposeAsync()

    Async terminates the ongoing binary import and puts the connection back into the idle state, where regular commands can be executed.

    Note that if CompleteAsync(CancellationToken) hasn't been invoked before calling this, the import will be cancelled and all changes will be reverted.

    Declaration
    public ValueTask DisposeAsync()
    Returns
    Type Description
    ValueTask
    Remarks

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

    | Improve this Doc View Source

    StartRow()

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

    Declaration
    public void StartRow()
    Remarks

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

    | Improve this Doc View Source

    StartRowAsync(CancellationToken)

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

    Declaration
    public Task StartRowAsync(CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Remarks

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

    | Improve this Doc View Source

    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 can 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.

    Remarks

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

    | Improve this Doc View Source

    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

    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.

    Remarks

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

    | Improve this Doc View Source

    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.

    Remarks

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

    | Improve this Doc View Source

    WriteAsync<T>(T, CancellationToken)

    Writes a single column in the current row.

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

    The value to be written

    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is .

    Returns
    Type Description
    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.

    Remarks

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

    | Improve this Doc View Source

    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 = null)
    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 can 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.

    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is .

    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    T

    The .NET type of the column to be written.

    Remarks

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

    | Improve this Doc View Source

    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 = null)
    Parameters
    Type Name Description
    T value

    The value to be written

    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.

    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is .

    Returns
    Type Description
    Task
    Type Parameters
    Name Description
    T

    The .NET type of the column to be written.

    Remarks

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

    | Improve this Doc View Source

    WriteNull()

    Writes a single null column value.

    Declaration
    public void WriteNull()
    Remarks

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

    | Improve this Doc View Source

    WriteNullAsync(CancellationToken)

    Writes a single null column value.

    Declaration
    public Task WriteNullAsync(CancellationToken cancellationToken = null)
    Parameters
    Type Name Description
    CancellationToken cancellationToken
    Returns
    Type Description
    Task
    Remarks

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

    | Improve this Doc View Source

    WriteRow(params 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
    object[] values

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

    Remarks

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

    | Improve this Doc View Source

    WriteRowAsync(CancellationToken, params 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 = null, params object[] values)
    Parameters
    Type Name Description
    CancellationToken cancellationToken

    An optional token to cancel the asynchronous operation. The default value is .

    object[] values

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

    Returns
    Type Description
    Task
    Remarks

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

    Implements

    IDisposable
    IAsyncDisposable
    • Improve this Doc
    • View Source
    In This Article
    Back to top © Copyright 2023 The Npgsql Development Team