Skip to content

Inconsistent behavior between libSQL server and SQLite for double-quoted strings #2075

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
riazus opened this issue May 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@riazus
Copy link

riazus commented May 22, 2025

Hello, I encountered a non-trivial issue that concerns both turso and drizzle-kit.

For deep understanding of the further explanations, I highly recommend you first to read the issue on @drizzle-kit side.

For adding the primary key to my table, I used the drizzle-kit generate command that generated the following SQL script:

PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_test_table` (
	`id` integer PRIMARY KEY NOT NULL,
	`name` text
);
--> statement-breakpoint
INSERT INTO `__new_test_table`("id", "name") SELECT "id", "name" FROM `test_table`;--> statement-breakpoint
DROP TABLE `test_table`;--> statement-breakpoint
ALTER TABLE `__new_test_table` RENAME TO `test_table`;--> statement-breakpoint
PRAGMA foreign_keys=ON;

NOTE: At the line "INSERT INTO __new_test_table("id", "name") SELECT "id", "name" FROM test_table;" we're trying to access the id column, but it doesn't exist yet.

The most important part related to Turso is when we're trying to apply migration changes to the database:

  • Applying changes to the remote database works without any errors. This is unexpected behavior, because the migration script is incorrect?
  • Applying changes to the local turso server (launched with the turso dev command) throws an error, which is the expected and correct behavior.
  • Applying the same changes directly using the sqlite3 command on the local database file does not throw an error. I'm not sure why this happens - it's very strange.

Versions of my packages:

$ turso --version
turso version v1.0.8
$ turso dev --version
sqld sqld 0.24.31 (e88c6b51 2025-01-06)
$ sqlite3 --version
3.43.2 2023-10-10 13:08:14 1b37c146ee9ebb7acd0160c0ab1fd11017a419fa8a3187386ed8cb32b709aapl (64-bit)
@penberg penberg added the bug Something isn't working label May 22, 2025
@penberg
Copy link
Collaborator

penberg commented May 22, 2025

Hey @riazus!

As you mention, SQLite is totally fine with the invalid query:

sqlite> CREATE TABLE `test_table` (`name` text);
sqlite> INSERT INTO test_table VALUES ('hello, world');
sqlite> SELECT "id", "name" FROM `test_table`;
id|hello, world

That's because SQLite treats double-quoted strings as literals unless they're a column:

https://www.sqlite.org/quirks.html#double_quoted_string_literals_are_accepted

The software on Turso Cloud is, therefore, the expected behavior as it follows SQLite's (arguably weird) semantics and the local dev server has a compatibility bug essentially.

@penberg penberg changed the title Inconsistent behavior between cloud and local turso server Inconsistent behavior between libSQL server and SQLite for double-quoted strings May 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants