Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for binary results #3317

Open
msand opened this issue Sep 19, 2024 · 0 comments
Open

Support for binary results #3317

msand opened this issue Sep 19, 2024 · 0 comments

Comments

@msand
Copy link

msand commented Sep 19, 2024

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 a some minor patches: #3316

Wdyt?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant