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

Enable pg parse bigint #3

Open
sidazhang opened this issue Mar 6, 2014 · 4 comments
Open

Enable pg parse bigint #3

sidazhang opened this issue Mar 6, 2014 · 4 comments

Comments

@sidazhang
Copy link

Can this be extended to support biginteger?

I have a few columns with BIGINT but they are all below 53 bits in length so I would like them to all be parsed as javascript integer. Can this module extend support?

@falconair
Copy link

I noticed the same issue. A large number of my columns are bigint, not only do their values in node show up as strings, but result set meta data also shows their 'format' as 'text'

@falconair
Copy link

Since this is a blocking issue for me, the following experiment worked for me:

...
  var types = {
    FLOAT4: 700,
    FLOAT8: 701,
    NUMERIC: 1700,
    BIGINT: 20,//<=
    INT8: 20,//<=
    FLOAT4_ARRAY: 1021,
    FLOAT8_ARRAY: 1022,
    NUMERIC_ARRAY: 1231
  };
  //just use the built-in V8 parseFloat implementation
  pg.types.setTypeParser(types.FLOAT4, 'text', parseFloat);
  pg.types.setTypeParser(types.FLOAT8, 'text', parseFloat);
  pg.types.setTypeParser(types.NUMERIC, 'text', parseFloat);
  pg.types.setTypeParser(types.BIGINT, 'text', parseFloat);//<=
  pg.types.setTypeParser(types.INT8, 'text', parseFloat);//<=
...

This isn't good enough for a pull request, since I probably didn't even need to add both, BIGINT and INT8. Hopefully this will be useful whoever gets stuck.

@brianc
Copy link
Owner

brianc commented Dec 1, 2014

Hi - sorry I missed the initial issue being opened up here. I'm totally down to add support for BIGINT as well. Do you want to submit a PR or do you want me to?

As for the format: text thing - that's actually a postgres protocol internal piece of information - you can ignore it. The postgres binary protocol can either operate in 'text mode' or 'binary mode.' The default is 'text mode.' It just means the data coming out is encoded in utf-8 text instead of binary. It's recommended to keep it in text mode unless you really know what you're doing and have a particular use case, as the binary mode is not as portable, and more difficult to parse.

@falconair
Copy link

@brianc go for it. I modified my file locally and it works but didn't do any testing or even investigate enough to make sure the change is good enough to be committed.

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

3 participants