GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — sqlite integer parameters should not be bound as doubles · Issue #63826 · nodejs/node

sqlite integer parameters should not be bound as doubles #63826

New issue
Copy link
New issue
Copy link
Closed
#67424
Closed
sqlite integer parameters should not be bound as doubles#63826
#67424
Copy link
Labels
questionIssues asking questions about Node.js.sqliteIssues and PRs related to the SQLite subsystem.

Description

@andrewitsover
andrewitsover
opened on Jun 10, 2026
Issue body actions

Version

v26.2.0

Platform

Darwin rocksteady 25.5.0 Darwin Kernel Version 25.5.0: Mon Apr 27 20:40:51 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T8112 arm64

Subsystem

sqlite

What steps will reproduce the bug?

I am assuming parameters that are number are always bound as type double, but integers should be bound as type integer so that SQLite performs integer arithmetic and returns a type of integer instead of a type of double.

const db = new DatabaseSync(':memory:', { readBigInts: true });
const big = db.prepare('select 2 * 2');
const bigResult = big.all();
const notBig = db.prepare('select 2 * ?');
const notResult = notBig.all(2);

This is the offending code in nodejs:

node/src/node_sqlite.cc

Line 2703 in 19c46ab

const double val = value.As<Number>()->Value();

How often does it reproduce? Is there a required condition?

Every time

What is the expected behavior? Why is that the expected behavior?

Integers should be bound as integers not double as they are integers.

What do you see instead?

Integers being bound as double.

Additional information

No response

Activity

  1. Renegade334 commented on Jun 10, 2026

    @Renegade334
    Renegade334
    on Jun 10, 2026
    Member
    More actions

    It would be very confusing indeed if the inferred storage class of the JS number type was not constant, which is what you're suggesting.

    A number in JS is a double; the only true integer primitive is bigint. In the (uncommon) instance where the storage class is inferred from JS input rather than being explicitly known by SQLite, the current type inference rules are entirely appropriate.

  2. Renegade334
    added
    questionIssues asking questions about Node.js.
    sqliteIssues and PRs related to the SQLite subsystem.
    on Jun 10, 2026
  3. andrewitsover commented on Jun 10, 2026

    @andrewitsover
    andrewitsover
    on Jun 10, 2026
    Author
    More actions

    From what I understand, SQLite chooses its storage class based on the actual value being stored, not based on whatever bind command you use. It is much more confusing that 3 / 2 returns different results depending on whether the 2 is a parameter or not!

    const db = new DatabaseSync(':memory:');
    const first = db.prepare('select 3 / 2');
    console.log(first.all()); // 1
    const second = db.prepare('select 3 / ?');
    console.log(second.all(2)); // 1.5

    Further, I don't know if this is the same code, but if so, bun does it how I would expect:

    https://github.com/oven-sh/bun/blob/09703da1aeb34e8415e700c0115cbf203e7b7351/src/jsc/bindings/sqlite/JSSQLStatement.cpp#L871

  4. Renegade334 commented on Jun 10, 2026

    @Renegade334
    Renegade334
    on Jun 10, 2026
    Member
    More actions

    Further, I don't know if this is the same code, but if so, bun does it how I would expect

    And better-sqlite3 uses the same convention as node:sqlite.

    @nodejs/sqlite opinions welcome!

  5. andrewitsover commented on Jun 10, 2026

    @andrewitsover
    andrewitsover
    on Jun 10, 2026
    Author
    More actions

    It is probably better to leave it how it is. Anyway, something to think about.

  6. TrevorBurnham commented on Aug 11, 2026

    @TrevorBurnham
    TrevorBurnham
    on Aug 11, 2026
    Contributor
    More actions

    Confirmed that:

    • better-sqlite3 binds integers as type double (the current node:sqlite behavior).
    • sqlite3-wasm binds integers as type integer (the proposed behavior), but with some caveats:
      • If the integer fits into and int32, it's always bound as integer.
      • If the integer is larger, it's bound as integer if BigInt is enabled, or as double otherwise.
    • bun's bun:sqlite binds integers as integer, while their node:sqlite module binds integers as double to match Node's behavior.

    I found some discussion of the better-sqlite3 behavior here: WiseLibs/better-sqlite3#627 (comment) I think the strongest argument for keeping the existing behavior is expressed in this comment:

    Yes. It would be much worse for better-sqlite3 to assume that any number without a fractional part is an INTEGER instead of a REAL. That would make it impossible to insert 666.0 into SQLite.

    That is, unlike other languages, JavaScript doesn't make a distinction between 666 and 666.0. Conversely, it does offer a way to make integers explicit: Append n, declaring it as a BigInt. So the "all number primitives are bound as double, all BigInts are bound as integer" rule makes it easy for devs to control the binding (if they know the rule).

    For that reason, I'd lean toward keeping the current behavior, and updating the docs to highlight the issue and to show BigInt use when working with integers:

    db.exec("create table t(k text primary key, v)");
    db.exec("insert into t values('3','found')");
    db.prepare('select v from t where k = ?').get(3);   // undefined
    db.prepare('select v from t where k = ?').get(3n);  // { v: 'found' }
    Reacted by René
  7. TrevorBurnham
    added 2 commits that reference this issue on Sep 4, 2026

    sqlite: add virtual table support via createModule()

    69f939a

    sqlite: add virtual table support via createModule()

    89b3a3a
  8. nodejs-github-bot
    added a commit that references this issue on Sep 22, 2026

    sqlite: add virtual table support via createModule()

    dd9f4da
  9. aduh95
    added a commit that references this issue on Sep 27, 2026

    sqlite: add virtual table support via createModule()

    b46b699
  10. araujogui commented on Oct 2, 2026

    @araujogui
    araujogui
    on Oct 2, 2026
    Member
    More actions

    +1 for keep keeping current behaviour

  11. TrevorBurnham commented on Nov 12, 2026

    @TrevorBurnham
    TrevorBurnham
    on Nov 12, 2026
    Contributor
    More actions

    I've sent over a PR to document the behavior (and the rationale for it) and close out this issue: #67424

  12. nodejs-github-bot
    closed this as completedin #67424on Nov 14, 2026
  13. LiviaMedeiros
    added a commit that references this issue on Nov 14, 2026

    doc: explain how sqlite binds numbers and BigInts

    b5e3a61
  14. aduh95
    added 2 commits that reference this issue on Nov 16, 2026

    doc: explain how sqlite binds numbers and BigInts

    a23a18b

    doc: explain how sqlite binds numbers and BigInts

    1151d51
  15. gabylb
    added a commit that references this issue on Nov 27, 2026

    doc: explain how sqlite binds numbers and BigInts

    8ce206e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues asking questions about Node.js.sqliteIssues and PRs related to the SQLite subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.