feedback icon indicating copy to clipboard operation
feedback copied to clipboard

SQL Cells should cast count(*) as numeric

Open nachocab opened this issue 2 years ago • 2 comments

Currently, a column with count(*) is interpreted as string (I'm testing on a PostgreSQL 13.11 database):

CleanShot 2023-07-30 at 09 46 59@2x

nachocab avatar Jul 30 '23 07:07 nachocab

For context, the reason is that PostgreSQL returns BIGINT which node-postgres casts to string for several reasons, one of them being that JS's BigInt type isn't JSON-serializable (see issue).

Luckily it's easy to cast to int yourself: select count(*)::int

mootari avatar Jul 30 '23 09:07 mootari

We should return it as bigint instead of string, though. I think initially bigint wasn’t widely supported so we used string, but now it is widely supported.

And frankly it’s so rare that you need bigint we should also just consider using int and losing precision if needed.

mbostock avatar Jul 31 '23 14:07 mbostock