Skip to content

Support for binary results #3317

Open
Open
@msand

Description

@msand

Hello, thanks for a wonderful pg library!

I'm trying to get binary support working, and have a minimal proof of concept here:

const pg = require("pg");

pg.types.setTypeParser(1184, "binary", (value) =>
  value === null ? null : value.readBigInt64BE(0),
);

async function getTimestamptzAsBigInt() {
  const client = new pg.Client({
    host: "localhost",
    user: "postgres",
    password: "postgres",
    database: "postgres",
    port: 5432,
    binary: true,
  });

  await client.connect();

  const result = await client.query({
    text: "SELECT current_timestamp;",
    queryMode: 'extended',
  });

  // This should be a BigInt representing number of microseconds
  // since midnight, January 1st, 2000
  console.log(result.rows[0].current_timestamp); 
  
  await client.end();
}

getTimestamptzAsBigInt().catch(console.error);

But it requires some minor patches: #3316

Wdyt?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions