question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'bigint' type is a string in query results.

See original GitHub issue

Following query returns a Postgres bigint for the assigned_client_count column (results of COUNT(*).

This is a string, rather than a Number, in the returned results.

{ __cid: '__cid40',
  method: 'select',
  options: undefined,
  bindings: [ 1 ],
  sql: 'select "id", "name", "fluid_account_id", "survey_fid", coalesce(assigned_client_count, 0) as assigned_client_count from (select "survey_id", count(*) as "assigned_client_count" from "client_surveys" group by "survey_id") as "t_counts" right join "fluid_surveys" on "t_counts"."survey_id" = "fluid_surveys"."id" where "fluid_account_id" = $1' }
 [ { id: 6,
    name: 'some name',
    fluid_account_id: 1,
    survey_fid: 69942,
    assigned_client_count: '1' } ]

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

49reactions
sidazhangcommented, Aug 8, 2014

@rhys-vdw , I have the same issue. The work around is add the following 2 lines above require('knex')

var pg = require('pg')
pg.types.setTypeParser(20, 'text', parseInt)
4reactions
bendruckercommented, Jul 21, 2014

So this is a node-postgres design decision and not really one we can abstract over either:

https://github.com/brianc/node-postgres/pull/353

node-postgres exposes its type parser so you can always override its default for bigint and run it against parseInt for all queries.

The problem here is that if you actually had big integers JS can’t natively deal with them. The default allows for full precision and you get the ability to opt out if you don’t need it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Different Examples of SQL BIGINT with Code and Output
BIGINT is a data type in standard query language (SQL) that is used to store exact number values. It is used to store...
Read more >
pg-promise returns integers as strings - node.js - Stack Overflow
bigint is 64-bit, and all 64-bit integers are returned by the underlying node-postgres driver as type string , while 32-bit ones are returned...
Read more >
INT vs BIGINT in SQL Server with Examples
SQL Server provides different categories of data types: Exact numerics, Unicode character strings, Approximate numerics, Binary strings.
Read more >
SQL Data Types
The CHARACTER data type accepts character strings, including Unicode, of a ... results in the truncation of the character string to the defined...
Read more >
Data types | BigQuery - Google Cloud
This assignment to x violates the type parameter constraint and results in an OUT_OF_RANGE error. SET x = "this string is too long"....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found