observablehq / feedback

Customer submitted bugs and feature requests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SQL Cells should cast count(*) as numeric

nachocab opened this issue · 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

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

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.