fix(pg_list_tables): cast reltuples to float8 so estimated_rows is a number#17
fix(pg_list_tables): cast reltuples to float8 so estimated_rows is a number#17HighviewOne wants to merge 2 commits into
Conversation
…number pg_class.reltuples is float4. Casting it to ::bigint gives an int8 result (OID 20), which node-pg parses as a string by default -- so estimated_rows was returning "42" (a JSON string) instead of 42 (a JSON number), contrary to the TypeScript annotation and every caller's expectation. Cast to ::float8 instead: reltuples is already approximate, float8 just widens the precision, and node-pg returns float8 as a JS number. Consistent with the pattern used by other numeric fields in health.ts and explain.ts. Adds a regression assertion to the integration test that verified typeof estimated_rows === "number" against a live database.
|
Review punch list for this PR. The core fix is correct: the handler generic at
🤖 Generated with Claude Code |
…fix description - NULLIF(round(c.reltuples), -1)::float8: rounds to integral row count (float4 sampling can produce 123456.75); maps PG 14+ never-analyzed sentinel (-1) to null so callers can distinguish "no estimate" from 0 - Description updated: "null = no ANALYZE yet on PG 14+; 0 may mean empty or unanalyzed on PG <= 13" - Integration test updated to accept number|null and assert integrality Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Addressed both review points:
|
What
pg_list_tablescastspg_class.reltuplesto::bigint. Node-pg parsesint8(OID 20) as a JavaScript string by default, soestimated_rowswas returning"42"(a JSON string) instead of42(a JSON number) — contrary to the TypeScript annotation and caller expectations.How
Cast to
::float8instead.reltuplesis alreadyfloat4(an approximate estimate), sofloat8just widens the precision. Node-pg returnsfloat8as a JS number correctly, and the TypeScript typenumberstays valid.This is consistent with how other numeric fields are handled in
health.tsandexplain.ts. The codebase's pattern for bigint counters is to cast to::text(for lossless serialization) —reltuplesdoesn't need that since it's already approximate.Test
Added a regression assertion to the integration test that checks
typeof estimated_rows === "number"against a live database. The existing test only checkednameandtype, so a revert would have been silent. All 87 integration tests pass.🤖 Generated with Claude Code