Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Fixed

- Fixed array column updates to properly handle empty arrays instead of incorrectly setting them to null.

## [v2.1.1] - 2025-03-12

### Changed
Expand Down
19 changes: 17 additions & 2 deletions crates/query-engine/translation/src/translation/query/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,26 @@ pub(crate) fn translate_projected(
let converted_element_exp =
translate_projected(env, state, type_name, element_expression)?;

// Create an empty array of the correct type to use as the default value
let empty_array = sql::ast::Expression::Cast {
expression: Box::new(sql::ast::Expression::Value(sql::ast::Value::Array(vec![]))),
r#type: sql::ast::ScalarType::ArrayType(type_to_ast_scalar_type_name(
env, type_name,
)?),
};

let mut result_select = sql::helpers::simple_select(vec![(
element_column,
// Use COALESCE to return an empty array instead of NULL when array_agg returns NULL
sql::ast::Expression::FunctionCall {
function: sql::ast::Function::Unknown("array_agg".to_string()),
args: vec![converted_element_exp],
function: sql::ast::Function::Coalesce,
args: vec![
sql::ast::Expression::FunctionCall {
function: sql::ast::Function::Unknown("array_agg".to_string()),
args: vec![converted_element_exp],
},
empty_array,
],
},
)]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"version": "5",
"$schema": "../../../../../../../static/configuration.schema.json",
"connectionSettings": {
"connectionUri": {
"variable": "CONNECTION_URI"
},
"poolSettings": {
"maxConnections": 50,
"poolTimeout": 30,
"idleTimeout": 180,
"checkConnectionAfterIdle": 60,
"connectionLifetime": 600
},
"isolationLevel": "ReadCommitted"
},
"metadata": {
"tables": {
"items": {
"schemaName": "public",
"tableName": "items",
"columns": {
"id": {
"name": "id",
"type": {
"scalarType": "int4"
},
"nullable": "nonNullable",
"description": null
},
"name": {
"name": "name",
"type": {
"scalarType": "text"
},
"nullable": "nullable",
"description": null
},
"tags": {
"name": "tags",
"type": {
"arrayType": {
"scalarType": "text"
}
},
"nullable": "nullable",
"description": null
}
},
"uniquenessConstraints": {
"items_pkey": ["id"]
},
"foreignRelations": {},
"description": null
}
},
"types": {
"scalar": {
"int4": {
"typeName": "int4",
"schemaName": "pg_catalog",
"description": null,
"aggregateFunctions": {},
"comparisonOperators": {},
"typeRepresentation": "int32"
},
"text": {
"typeName": "text",
"schemaName": "pg_catalog",
"description": null,
"aggregateFunctions": {},
"comparisonOperators": {},
"typeRepresentation": "string"
}
},
"composite": {}
},
"nativeOperations": {
"queries": {},
"mutations": {}
}
},
"introspectionOptions": {
"excludedSchemas": [
"information_schema",
"pg_catalog",
"tiger",
"crdb_internal",
"columnar",
"columnar_internal"
],
"unqualifiedSchemasForTables": ["public"],
"unqualifiedSchemasForTypesAndProcedures": [
"public",
"pg_catalog",
"tiger"
],
"typeRepresentations": {
"bit": "string",
"bool": "boolean",
"bpchar": "string",
"char": "string",
"date": "date",
"float4": "float32",
"float8": "float64",
"int2": "int16",
"int4": "int32",
"int8": "int64AsString",
"numeric": "bigDecimalAsString",
"text": "string",
"time": "time",
"timestamp": "timestamp",
"timestamptz": "timestamptz",
"timetz": "timetz",
"uuid": "uUID",
"varchar": "string"
}
},
"mutationsVersion": "v2",
"mutationsPrefix": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "../../../../../../../static/mutation.schema.json",
"operations": [
{
"type": "procedure",
"name": "v2_update_items_by_id",
"arguments": {
"key_id": 1,
"update_columns": {
"tags": {
"_set": []
}
}
},
"fields": {
"type": "object",
"fields": {
"affected_rows": {
"type": "column",
"column": "affected_rows"
},
"returning": {
"type": "column",
"column": "returning",
"fields": {
"type": "array",
"fields": {
"type": "object",
"fields": {
"id": {
"type": "column",
"column": "id"
},
"tags": {
"type": "column",
"column": "tags"
}
}
}
}
}
}
}
}
],
"collection_relationships": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
"version": "5",
"$schema": "../../../../../../../static/configuration.schema.json",
"connectionSettings": {
"connectionUri": {
"variable": "CONNECTION_URI"
},
"poolSettings": {
"maxConnections": 50,
"poolTimeout": 30,
"idleTimeout": 180,
"checkConnectionAfterIdle": 60,
"connectionLifetime": 600
},
"isolationLevel": "ReadCommitted"
},
"metadata": {
"tables": {
"items": {
"schemaName": "public",
"tableName": "items",
"columns": {
"id": {
"name": "id",
"type": {
"scalarType": "int4"
},
"nullable": "nonNullable",
"description": null
},
"name": {
"name": "name",
"type": {
"scalarType": "text"
},
"nullable": "nullable",
"description": null
},
"tags": {
"name": "tags",
"type": {
"arrayType": {
"scalarType": "text"
}
},
"nullable": "nullable",
"description": null
}
},
"uniquenessConstraints": {
"items_pkey": ["id"]
},
"foreignRelations": {},
"description": null
}
},
"types": {
"scalar": {
"int4": {
"typeName": "int4",
"schemaName": "pg_catalog",
"description": null,
"aggregateFunctions": {},
"comparisonOperators": {},
"typeRepresentation": "int32"
},
"text": {
"typeName": "text",
"schemaName": "pg_catalog",
"description": null,
"aggregateFunctions": {},
"comparisonOperators": {},
"typeRepresentation": "string"
}
},
"composite": {}
},
"nativeOperations": {
"queries": {},
"mutations": {}
}
},
"introspectionOptions": {
"excludedSchemas": [
"information_schema",
"pg_catalog",
"tiger",
"crdb_internal",
"columnar",
"columnar_internal"
],
"unqualifiedSchemasForTables": ["public"],
"unqualifiedSchemasForTypesAndProcedures": [
"public",
"pg_catalog",
"tiger"
],
"typeRepresentations": {
"bit": "string",
"bool": "boolean",
"bpchar": "string",
"char": "string",
"date": "date",
"float4": "float32",
"float8": "float64",
"int2": "int16",
"int4": "int32",
"int8": "int64AsString",
"numeric": "bigDecimalAsString",
"text": "string",
"time": "time",
"timestamp": "timestamp",
"timestamptz": "timestamptz",
"timetz": "timetz",
"uuid": "uUID",
"varchar": "string"
}
},
"mutationsVersion": "v2",
"mutationsPrefix": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "../../../../../../../static/mutation.schema.json",
"operations": [
{
"type": "procedure",
"name": "v2_update_items_by_id",
"arguments": {
"key_id": 1,
"update_columns": {
"tags": {
"_set": null
}
}
},
"fields": {
"type": "object",
"fields": {
"affected_rows": {
"type": "column",
"column": "affected_rows"
},
"returning": {
"type": "column",
"column": "returning",
"fields": {
"type": "array",
"fields": {
"type": "object",
"fields": {
"id": {
"type": "column",
"column": "id"
},
"tags": {
"type": "column",
"column": "tags"
}
}
}
}
}
}
}
}
],
"collection_relationships": {}
}
Loading
Loading