Repository navigation
Open
Milestone
Description
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
- Add a conversion module with one function per declared type family,
toColumn(value, column). Every type name maps to a family, soINT,INTEGER,BIGINTandINT8convert alike, and so doFLOAT,REAL,DOUBLE PRECISION,NUMBER,DECIMALandMONEY.- NULL and
undefinedgivenull. - 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,DATEand the types inalasql.fn, keep whatINSERT ... VALUESdoes today.
- NULL and
- The write pipeline of Pass the rows of INSERT, UPDATE and DELETE through one write pipeline #2650 calls
toColumnonce per value for every insert and update.SELECT ... INTO tablegoes through the same pipeline after Let modifiers and INTO formats only read the finished result #2699. - Remove
alasql.utils.typeConverterand the conversion code insrc/statements/insert.js. - Add the rule
columnConversionto Rules that differ between dialects become named rules chosen when a statement is compiled #3170 with the valuesaffinity(the new default) andv4. Withv4each path keeps its 4.x rule. Add it toalasql/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. CASTis not changed in this step.- With
alasql/dialect/v4every path stores what it stores in 4.x. - In the default,
INSERT ... SELECT,UPDATEandSELECT ... INTOstore converted values, and text that is not a number stays text instead ofNaN.
Done when
- A new test file named after this issue writes the same values through
INSERT ... VALUES,INSERT ... SELECT,UPDATEandSELECT ... INTOinto a table withINT,FLOAT,STRINGandBOOLEANcolumns and checks that all four store the same row, with and withoutalasql/dialect/v4. It includes'abc'and NULL intoINTandFLOAT. - 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.
Activity
[-]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[/+]