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.

count field filled with string at runtime, even though type is number

See original GitHub issue

I’ve got a query defined like this:

/* @name CountByName */ SELECT COUNT(*) FROM users WHERE username = :username;

But at runtime it’s returning [{count:"0"}].

What might I be doing wrong?

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
adelszcommented, Jun 27, 2020

In PG SQL queries count is returned as bigint. PG’s bigint can be bigger than JS’s Number.MAX_SAFE_INTEGER so it is parsed as string by node-postgres. If you are sure that your counts will fit into int4 then a potential workaround is to typecast the count to int in your query:

SELECT COUNT(*)::int FROM users WHERE username = :username; 
0reactions
adelszcommented, Jun 30, 2020

Ok, If I understood you correctly, casting COUNT(*)::int solved the issue you were having. Closing this issue, let me know that is not the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Counting words in string - javascript - Stack Overflow
This code counts words that contain only alphanumeric characters and "_", "'", "-", "'" chars.
Read more >
Write a function that counts the number of times a given int ...
Given a singly linked list and a key, count the number of occurrences of the given key in the linked list. For example,...
Read more >
VBA Type Mismatch Error - The Ultimate Guide
The VBA Type Mismatch error is very common in Excel VBA. It is caused by trying to assign between two different variable types....
Read more >
Documentation - Everyday Types - TypeScript
JavaScript has three very commonly used primitives: string , number , and boolean . Each has a corresponding type in TypeScript. As you...
Read more >
Built-in Types — Python 3.11.1 documentation
Objects of different types, except different numeric types, never compare ... as binary numbers, converting a float to or from a decimal string...
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