Commit Graph

961 Commits

Author SHA1 Message Date
PThorpe92
ace2ac632a Remove semicolon from test 2025-09-27 13:59:51 -04:00
PThorpe92
6e3c30623c Fix regression test to not use dot command 2025-09-27 13:17:50 -04:00
PThorpe92
bd17c5d5df Add regression test for alter table with notnull constraint 2025-09-27 13:15:48 -04:00
Pekka Enberg
9eb6f4b51e Merge 'Sqlean fuzzy string ' from Danawan Bimantoro
Add implementations of string distance and phonetics functions:
fuzzy_damlev
fuzzy_hamming
fuzzy_jarowin
fuzzy_leven
fuzzy_osadist
fuzzy_editdist
fuzzy_soundex
fuzzy_rsoundex
fuzzy_phonetic
fuzzy_caver
fuzzy_translit
This implementation follows sqlean-fuzzy

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3262
2025-09-27 16:51:49 +03:00
Pekka Enberg
d7a0a3db56 Merge 'core/translate: allow creating column called 'rowid'' from Preston Thorpe
closes #3282
includes minor refactor, removing `column_is_rowid_alias`, which is only
checking the public field of the argument Column.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3385
2025-09-27 16:51:09 +03:00
Pekka Enberg
5ff0044961 Merge 'length shall not count when it sees nullc' from Pavan Nambi
fixes #3317

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3356
2025-09-27 16:50:50 +03:00
Glauber Costa
3ee97ddf36 Make sure complex expressions in filters go through Project
We had code for this, but the code had a fatal flaw: it tried to detect
a complex operation (an operation that needs projection), and return
false (no need for projection), for the others.

This is the exact opposite of what we should do: we should identify the
*simple* operations, and then return true (needs projection) for the
rest.

CAST is a special beast, since it is not a function, but rather, a
special opcode. Everything else above is the true just the same. But for
CAST, we have to do the extra work to capture it in the logical plan and
pass it down.

Fixes #3372
Fixes #3370
Fixes #3369
2025-09-27 07:21:03 -03:00
Danawan Bimantoro
a58c6a3c0b Merge branch 'main' into main 2025-09-27 11:05:44 +07:00
PThorpe92
abab04dac9 Add regression test for col named rowid 2025-09-26 17:33:53 -04:00
Pavan-Nambi
fdabbed539 length shall not count when it sees nullc 2025-09-26 15:07:33 +05:30
danawan
468046c654 translit and script 2025-09-26 15:20:27 +07:00
Jussi Saurio
cfa449a0c0 Merge 'Disallow multiple primary keys in table definition' from Jussi Saurio
Closes #3309

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #3340
2025-09-26 09:16:14 +03:00
Jussi Saurio
064cc04b69 Merge 'Fix CREATE INDEX with quoted identifiers' from Iaroslav Zeigerman
Discovered this one while working on #3322
It was a bit more elusive because the original error was essentially a
red herring:
```
turso> CREATE INDEX idx ON "t t" (`a a`);
  × unexpected token at SourceSpan { offset: SourceOffset(22), length: 1 }
   ╭────
 1 │ CREATE INDEX idx ON "t t" (`a a`);
   ·                       ┬
   ·                       ╰── here
   ╰────
  help: expected [TK_LP] but found TK_ID
```

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3345
2025-09-26 09:13:30 +03:00
Jussi Saurio
c83ee9fc3e Merge 'Fix ungrouped aggregate with offset clause' from Preston Thorpe
closes #3300

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3347
2025-09-26 09:13:16 +03:00
Jussi Saurio
9549ca5d51 Merge 'translate/update: allow for updating nonalias'd rowid column explicitly ' from Preston Thorpe
closes #3276

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3349
2025-09-26 09:13:03 +03:00
Jussi Saurio
6d6fc91da3 Disallow multiple primary keys in table definition 2025-09-26 08:59:36 +03:00
PThorpe92
04de70fd66 Update test to reflect lack of err message when .schema nonexistant table is ran 2025-09-25 19:44:42 -04:00
PThorpe92
9d4dee01fb Add regression test for explicit rowid update 2025-09-25 19:16:20 -04:00
PThorpe92
05cab4bb91 Add test for ungrouped aggregate with offset 2025-09-25 16:47:26 -04:00
Preston Thorpe
d44a1f8bca Merge 'Implement json_tree' from Mikaël Francoeur
This PR implements the `json_tree` table-valued function.
It's not 100% compatible with SQLite, because SQLite does some iffy
things with the `key` and `path` columns. I started a
[thread](https://www.sqlite.org/forum/forumpost/48f5763d8c) on their
forum and I linked it to the disabled tests in `json.test`.

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3256
2025-09-25 16:45:44 -04:00
Iaroslav Zeigerman
b34e53d6c6 Fix CREATE INDEX with quoted identifiers 2025-09-25 12:55:06 -07:00
Pekka Enberg
c255e456d6 Merge 'Fix incorrect "column is ambiguous" error with USING clause' from Jussi Saurio
Closes #3299

Closes #3343
2025-09-25 21:02:36 +03:00
Pekka Enberg
b3a0008950 Merge 'parser: fix incorrect LIMIT/OFFSET parsing of form LIMIT x,y' from Jussi Saurio
In this case x is the OFFSET and y is the LIMIT, not the other way
around.
Closes #3303

Closes #3339
2025-09-25 21:01:40 +03:00
Pere Diaz Bou
91cff65e44 Merge 'Autoincrement' from Pavan Nambi
fixes #1976
and #1605
```zsh
turso> DROP TABLE IF EXISTS t;
CREATE TABLE t (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
);
turso> INSERT INTO t (name) VALUES ('A'); SELECT * FROM sqlite_sequence;
┌──────┬─────┐
│ name │ seq │
├──────┼─────┤
│ t    │   1 │
└──────┴─────┘
turso> DROP TABLE IF EXISTS t;
CREATE TABLE t (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT
);
turso> INSERT INTO t (name) VALUES ('A'); SELECT * FROM sqlite_sequence;
┌──────┬─────┐
│ name │ seq │
├──────┼─────┤
│ t    │   1 │
└──────┴─────┘
turso> INSERT INTO t (name) VALUES ('A'); SELECT * FROM sqlite_sequence;
┌──────┬─────┐
│ name │ seq │
├──────┼─────┤
│ t    │   2 │
└──────┴─────┘
turso>
```

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #2983
2025-09-25 18:57:24 +02:00
Pekka Enberg
f8130d051f Merge 'Fix JavaScript bindings' from Nikita Sivukhin
This PR makes all JS db packages to have uniform interface: `new
Database(...)` constructor with explicit `connect()` and `close()`
methods.
Also, this PR adds docstrings in the code and properly support few
better-sqlite options (readonly, fileMustExist, timeout)

Closes #3334
2025-09-25 17:24:03 +03:00
Jussi Saurio
00466aa84e Fix incorrect "column is ambiguous" error with USING clause 2025-09-25 16:06:40 +03:00
Jussi Saurio
bb082c25f5 Fix incorrect LIMIT/OFFSET parsing of form LIMIT x,y
In this case x is the OFFSET and y is the LIMIT, not the
other way around.
2025-09-25 15:10:14 +03:00
danawan
189caa5d5d rsoundex 2025-09-25 16:10:34 +07:00
Jussi Saurio
8f46721848 Merge 'Normalize target table name identifier on table or column rename' from Iaroslav Zeigerman
Closes #3320
Closes #3286
In addition to the problem reported in the ticket, 2 more issues were
identified:
1. Renaming a column for a table with a special character in its name
failed with
```
turso> CREATE TABLE `t t`(a);
turso> ALTER TABLE `t t` RENAME COLUMN a TO `a a`;

thread 'main' panicked at core/vdbe/execute.rs:7870:14:
table being renamed should be in schema
```
2. The renamed table in the `sql` column of `sqlite_schema` was not
reflected correctly after renaming:
```
turso>  select * from sqlite_schema;
┌───────┬──────┬──────────┬──────────┬──────────────────────┐
│ type  │ name │ tbl_name │ rootpage │ sql                  │
├───────┼──────┼──────────┼──────────┼──────────────────────┤
│ table │ t t  │ t t      │        2 │ CREATE TABLE t t (a) │
└───────┴──────┴──────────┴──────────┴──────────────────────┘
```
3. `sql` for indexes was not reflected correctly after renaming a column
that contains special characters:
```
turso> ALTER TABLE `t t` RENAME COLUMN `a a` TO `b b`;
turso> SELECT sql FROM sqlite_schema;

┌───────────────────────────────────┐
│ sql                               │
├───────────────────────────────────┤
│ CREATE TABLE `t t` (`b b`)        │
├───────────────────────────────────┤
│ CREATE INDEX idx ON `t t` (`a a`) │
├───────────────────────────────────┤
```

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3322
2025-09-25 11:41:45 +03:00
Nikita Sivukhin
6015dee36e fix tests in testing/javascript 2025-09-25 12:07:57 +04:00
Pekka Enberg
b81cc1da1d Merge 'Fix: NULL values in group_concat()' from
Closes #3304.
group_concat() now ignores null values.

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #3321
2025-09-25 10:19:41 +03:00
Iaroslav Zeigerman
4799f23261 Fix: Normalize the target table name identifier when renaming a table / column 2025-09-24 22:23:04 -07:00
Jussi Saurio
c18c44b032 fix: result columns have varying binding precedence
In e.g. `SELECT x AS y, y AS x FROM t ORDER BY x;`, the `x` in the
`ORDER BY` should reference t.y, which has been aliased as `x` for this
query. The same goes for GROUP BY, JOIN ON etc. but NOT for WHERE.

Previously we had wrong precedence in `bind_and_rewrite_expr`.
2025-09-25 08:07:37 +03:00
danawan
54a95a0b55 add caverphone 2025-09-25 10:25:12 +07:00
rajajisai
b9ef9d6c63 Ignore null values in group concat 2025-09-24 18:11:02 -04:00
Pavan-Nambi
49d5141f2d Merge remote-tracking branch 'origin/main' into cdc_fail_autoincrement 2025-09-24 18:06:02 +05:30
danawan
91e40e7431 Merge remote-tracking branch 'upstream/main' 2025-09-24 15:42:07 +07:00
Pekka Enberg
d0e15f9ac0 Merge 'Fix INSERT INTO t DEFAULT VALUES' from Jussi Saurio
Closes #3279

Closes #3291
2025-09-24 11:09:27 +03:00
danawan
815f0ffe25 add phonetic and soundex 2025-09-24 13:58:19 +07:00
Jussi Saurio
5c82b72e5f fix INSERT INTO t DEFAULT VALUES 2025-09-24 09:54:43 +03:00
Jussi Saurio
726bc24e78 Support referring to rowid as _rowid_ or oid 2025-09-24 09:17:28 +03:00
Danawan Bimantoro
c3132d0368 Merge branch 'tursodatabase:main' into main 2025-09-24 13:05:41 +07:00
Jussi Saurio
73571d9c55 Merge 'Don't allow duplicate columns and get column type as passed ' from Pavan Nambi
fixes #3231
```zsh

❯ sqlite3
SQLite version 3.50.4 2025-07-30 19:33:53
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>   CREATE TABLE t1 (a);
    ALTER TABLE t1 ADD COLUMN a;
Parse error: duplicate column name: a
sqlite>   ALTER TABLE t1 ADD COLUMN name varchar(255);
    SELECT sql FROM sqlite_schema WHERE name = 't1';
CREATE TABLE t1 (a, name varchar(255))
sqlite>
```
```zsh
turso>
turso>  CREATE TABLE t1 (a);
    ALTER TABLE t1 ADD COLUMN a;
  x Parse error: duplicate column name: a

turso>  ALTER TABLE t1 ADD COLUMN name varchar(255);
    SELECT sql FROM sqlite_schema WHERE name = 't1';
┌─────────────────────────────────────────┐
│ sql                                     │
├─────────────────────────────────────────┤
│ CREATE TABLE t1 (a, name varchar (255)) │
└─────────────────────────────────────────┘
turso>
```

Reviewed-by: Pere Diaz Bou <pere-altea@homail.com>

Closes #3249
2025-09-24 09:04:08 +03:00
Jussi Saurio
d5de088abe Merge 'translate: implement Sequence opcode and fix sort order' from Preston Thorpe
This PR implements the `Sequence` and `SequenceTest` opcodes, although
does not yet add plumbing to emit the latter.
SQLite has two distinct mechanisms that determine the final row order
with aggregates:
Traversal order of GROUP BY, and ORDER BY tiebreaking. When ORDER BY
contains only aggregate expressions and/or constants, SQLite has no
extra tiebreak key, but when ORDER BY mixes aggregate and non-aggregate
terms, SQLite adds an implicit, stable row `sequence` so “ties” respect
the input order.
This PR also fixes an issue with a query like the following:
```sql
SELECT u.first_name, COUNT(*) AS c
FROM users u
JOIN orders o ON o.user_id = u.id
GROUP BY u.first_name
ORDER BY c DESC;
```
Because ORDER BY has only an aggregate (COUNT(*) DESC) and no non-
aggregate terms, SQLite traverses the group key (u.first_name) in DESC
order in this case, so ties on c naturally appear with group keys in
descending order.
Previously tursodb would return the group key sorted in ASC order,
because it was used in all cases as the default

Closes #3287
2025-09-24 08:38:08 +03:00
PThorpe92
4cc02dbed1 Add regression test for sort order with aggregate term in orderby with groupby 2025-09-23 23:08:31 -04:00
Mikaël Francoeur
3e915d9868 implement json_tree 2025-09-23 14:22:02 -04:00
Pavan-Nambi
59660f0c25 remove tests for column type spaces 2025-09-23 12:48:35 +05:30
danawan
80508910ea ruff check --fix 2025-09-23 13:28:13 +07:00
Pavan-Nambi
8e02855c98 update seq table onconflict nothing too and refactor logic into seperate function
add testcase for failed fuzz

more

remove autoincrement if col aint integer

fmt
2025-09-23 11:41:52 +05:30
danawan
16b706a8d4 add sqlean fuzzy string distances 2025-09-23 11:49:41 +07:00