Postgres module

copy_in

procedure · 2 overloadssince 0.27.0Source

Sends rows through sql, a copy <table> (<columns>) from stdin (format binary) statement, and returns how many rows the server stored. Each row sends the members named in columns, in that order, or every member when columns is empty. The columns' types must match the members' binary forms exactly (an s32 for int4, an s64 for int8): COPY casts nothing. A Json(T) member goes as jsonb unless it has the @pg_json note, which sends it as json.

Example
stored, error := Pg.copy_in(db, "copy users (email, score) from stdin (format binary)", users, .["email", "score"]);

Not run: the example is marked ignore.

Not run: it needs a PostgreSQL server.

copy_in :: (
    c: *Connection,
    sql: string,
    rows: [] $Row,
    columns: [] string = .[]
) -> (s64, Pg_Error)

Sends rows through sql, a copy <table> (<columns>) from stdin (format binary) statement, and returns how many rows the server stored. Each row sends the members named in columns, in that order, or every member when columns is empty. The columns' types must match the members' binary forms exactly (an s32 for int4, an s64 for int8): COPY casts nothing. A Json(T) member goes as jsonb unless it has the @pg_json note, which sends it as json.

Not run: it needs a PostgreSQL server.

Parameters

c: *Connection
the connection to run on.
sql: string
the copy ... from stdin (format binary) statement.
rows: [] $Row
the structs to send, one per row.
columns: [] string
the members to send, in column order. Empty sends every member.

Returns

s64
Example
stored, error := Pg.copy_in(db, "copy users (email, score) from stdin (format binary)", users, .["email", "score"]);

Not run: the example is marked ignore.

copy_in :: (
    pool: *Pool,
    sql: string,
    rows: [] $Row,
    columns: [] string = .[]
) -> (s64, Pg_Error)

copy_in on a connection from the pool.

Parameters

pool: *Pool
the pool to take a connection from. It is returned afterwards.
sql: string
the copy ... from stdin (format binary) statement.
rows: [] $Row
the structs to send, one per row.
columns: [] string
the members to send, in column order. Empty sends every member.

Returns

s64

See also