observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

SQL Cells should cast count(*) as numeric #586

Open nachocab opened 11 months ago

nachocab commented 11 months ago

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
mootari commented 11 months ago

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

mbostock commented 11 months ago

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.