sqlparser: Support new SQL functions

This commit is contained in:
Simon Binder 2023-10-24 22:56:12 +02:00
parent 559cf986a1
commit 222dc3063e
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
4 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@
- Treat the result of `sum()` as nullable when inferring types.
- Support features added in sqlite 3.44:
- `ORDER BY` clauses as part of aggregate functions.
- Support `concat`, `concat_ws` and `string_agg`.
## 0.32.0

View File

@ -278,6 +278,7 @@ class LintingVisitor extends RecursiveVisitor<void, void> {
'format' || 'unixepoch' => SqliteVersion.v3_38,
'unhex' => SqliteVersion.v3_41,
'timediff' || 'octet_length' => SqliteVersion.v3_43,
'concat' || 'concat_ws' || 'string_agg' => SqliteVersion.v3_44,
_ => null,
};

View File

@ -573,7 +573,16 @@ class TypeResolver extends RecursiveVisitor<TypeExpectation, void> {
case 'upper':
nullableIfChildIs();
return _textType.withoutNullabilityInfo;
case 'concat':
return _textType;
case 'concat_ws':
// null if the first argument is null
if (params.isNotEmpty) {
session._addRelation(NullableIfSomeOtherIs(e, [params.first]));
}
return _textType.withoutNullabilityInfo;
case 'group_concat':
case 'string_agg':
return _textType.withNullable(true);
case 'date':
case 'time':

View File

@ -66,6 +66,12 @@ const Map<String, ResolvedType?> _types = {
"SELECT unhex('ab') = ?": ResolvedType(type: BasicType.blob, nullable: true),
'SELECT unhex(?)': ResolvedType(type: BasicType.text),
'SELECT 1 GROUP BY 1 HAVING ? ': ResolvedType.bool(),
"SELECT concat(1, NULL, 2) = ?":
ResolvedType(type: BasicType.text, nullable: false),
"SELECT concat_ws(',', 1, 2) = ?":
ResolvedType(type: BasicType.text, nullable: false),
"SELECT concat_ws(NULL, 1, 2) = ?":
ResolvedType(type: BasicType.text, nullable: true),
};
SqlEngine _spawnEngine() {