Skip to content

Commit 61afdce

Browse files
committed
Wrap UPDATE subqueries in IFNULL to fix NOT NULL violations
Turso's aggregate-without-GROUP-BY returns 0 rows when the WHERE clause matches nothing (SQL standard requires 1 row with NULL aggregates). Zero rows from a scalar subquery yields NULL, which violates the NOT NULL constraint on is_nullable. Wrap each subquery in IFNULL(..., c.<col>) so no-match cases keep the existing value.
1 parent 6d1ae96 commit 61afdce

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

.github/workflows/phpunit-tests-turso.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,13 +485,18 @@ jobs:
485485
"\t\t);"
486486
)
487487
assert old in src, 'sync_column_key_info UPDATE not found'
488+
# Wrap each subquery in IFNULL(..., c.<col>) because Turso's
489+
# aggregate-without-GROUP-BY returns zero rows when the WHERE
490+
# matches nothing (SQL standard requires one row with NULL
491+
# aggregates). Zero rows from a scalar subquery means NULL, which
492+
# violates the NOT NULL constraint on is_nullable.
488493
new = "\n".join([
489494
"\t\t$columns_table = $this->connection->quote_identifier( $columns_table_name );",
490495
"\t\t$statistics_table = $this->connection->quote_identifier( $statistics_table_name );",
491496
"\t\t$this->connection->query(",
492497
"\t\t\t\"",
493498
"\t\t\t\tUPDATE $columns_table AS c",
494-
"\t\t\t\tSET column_key = (",
499+
"\t\t\t\tSET column_key = IFNULL((",
495500
"\t\t\t\t\tSELECT",
496501
"\t\t\t\t\t\tCASE",
497502
"\t\t\t\t\t\t\tWHEN MAX(s.index_name = 'PRIMARY') THEN 'PRI'",
@@ -503,8 +508,8 @@ jobs:
503508
"\t\t\t\t\tWHERE s.table_schema = c.table_schema",
504509
"\t\t\t\t\tAND s.table_name = c.table_name",
505510
"\t\t\t\t\tAND s.column_name = c.column_name",
506-
"\t\t\t\t),",
507-
"\t\t\t\tis_nullable = (",
511+
"\t\t\t\t), c.column_key),",
512+
"\t\t\t\tis_nullable = IFNULL((",
508513
"\t\t\t\t\tSELECT",
509514
"\t\t\t\t\t\tCASE",
510515
"\t\t\t\t\t\t\tWHEN MAX(s.index_name = 'PRIMARY') THEN 'NO'",
@@ -514,7 +519,7 @@ jobs:
514519
"\t\t\t\t\tWHERE s.table_schema = c.table_schema",
515520
"\t\t\t\t\tAND s.table_name = c.table_name",
516521
"\t\t\t\t\tAND s.column_name = c.column_name",
517-
"\t\t\t\t)",
522+
"\t\t\t\t), c.is_nullable)",
518523
"\t\t\t\tWHERE c.table_schema = ?",
519524
"\t\t\t\tAND c.table_name = ?",
520525
"\t\t\t\",",

0 commit comments

Comments
 (0)