Skip to content

Convert values for a typed column in one function, used by every write into a table #2659

Open

Description

@mathiasrw

What happens today

A value written into a column with a declared type is converted differently on each path.

Path Where Rule
INSERT ... VALUES src/statements/insert.js +value for INT, FLOAT, NUMBER, MONEY, new T(value) for a type in alasql.fn
INSERT ... SELECT src/statements/insert.js none
UPDATE ... SET src/statements/update.js none
SELECT ... INTO table alasql.utils.typeConverter in src/utils/helpers.js parseInt, parseFloat, String(), 'yes' to true
alasql('CREATE TABLE t2 (i INT, s STRING, b BOOLEAN)');
alasql('SELECT "12" AS i, 3 AS s, "yes" AS b INTO t2');        // stores {i: 12, s: '3', b: true}
alasql('INSERT INTO t2 SELECT "13" AS i, 4 AS s, "yes" AS b'); // stores {i: '13', s: 4, b: 'yes'}

What to change

  1. Add a conversion module with one function per declared type family, toColumn(value, column). Every type name maps to a family, so INT, INTEGER, BIGINT and INT8 convert alike, and so do FLOAT, REAL, DOUBLE PRECISION, NUMBER, DECIMAL and MONEY.
    • NULL and undefined give null.
    • For the number types, text that reads as a number becomes the number. Other text stays as it is.
    • For the text types, numbers become text.
    • For BOOLEAN, DATE and the types in alasql.fn, keep what INSERT ... VALUES does today.
  2. The write pipeline of Pass the rows of INSERT, UPDATE and DELETE through one write pipeline #2650 calls toColumn once per value for every insert and update. SELECT ... INTO table goes through the same pipeline after Let modifiers and INTO formats only read the finished result #2699.
  3. Remove alasql.utils.typeConverter and the conversion code in src/statements/insert.js.
  4. Add the rule columnConversion to Rules that differ between dialects become named rules chosen when a statement is compiled #3170 with the values affinity (the new default) and v4. With v4 each path keeps its 4.x rule. Add it to alasql/dialect/v4.

What stays the same

  • Values that already have the declared type are stored unchanged.
  • Tables without declared columns and FROM ? are not converted.
  • CAST is not changed in this step.
  • With alasql/dialect/v4 every path stores what it stores in 4.x.
  • In the default, INSERT ... SELECT, UPDATE and SELECT ... INTO store converted values, and text that is not a number stays text instead of NaN.

Done when

  • A new test file named after this issue writes the same values through INSERT ... VALUES, INSERT ... SELECT, UPDATE and SELECT ... INTO into a table with INT, FLOAT, STRING and BOOLEAN columns and checks that all four store the same row, with and without alasql/dialect/v4. It includes 'abc' and NULL into INT and FLOAT.
  • The dialect test against SQLite gets cases that insert text and numbers into typed columns and read them back.
  • The full test suite and the CI checks (dialect test, parity check, run-state check, binding check) pass, and the pull request lists every parity difference.

Fixes

Fixes #2590, #316, #2816.

Depends on

#2699, #3169, #2650, #3170, #2588

Activity

  1. added this to the v5.0.0 milestone on Nov 9, 2026
  2. changed the title [-]Review #2403 for code improvements: a second set of type conversion rules for SELECT INTO[/-] [+]Convert values for a typed column in one function, used by every write into a table[/+] on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions