Enhance aggregation functions in SQL queries for improved PostgreSQL compatibility

This commit is contained in:
SPRINX0\prochazka
2026-04-08 10:55:24 +02:00
parent 6b4f6b909c
commit af7930cea2
3 changed files with 14 additions and 12 deletions

View File

@@ -72,6 +72,8 @@ class Analyser extends DatabaseAnalyser {
...replacements,
$typeAggFunc: this.driver.dialect.stringAgg ? 'string_agg' : 'max',
$typeAggParam: this.driver.dialect.stringAgg ? ", '|'" : '',
$hashColumnAggTail: this.driver.dialect.stringAgg ? ", ',' ORDER BY a.attnum" : '',
$hashConstraintAggTail: this.driver.dialect.stringAgg ? ", ',' ORDER BY con.conname" : '',
$md5Function: this.dialect?.isFipsComplianceOn ? 'LENGTH' : 'MD5',
});
return query;

View File

@@ -5,9 +5,9 @@ SELECT
pg_relation_size(c.oid) AS "size_bytes",
$md5Function(
COALESCE(
(SELECT string_agg(
a.attname || ':' || pg_catalog.format_type(a.atttypid, a.atttypmod) || ':' || a.attnotnull::text,
',' ORDER BY a.attnum
(SELECT $typeAggFunc(
a.attname || ':' || pg_catalog.format_type(a.atttypid, a.atttypmod) || ':' || a.attnotnull::text
$hashColumnAggTail
)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = c.oid AND a.attnum > 0 AND NOT a.attisdropped),
@@ -16,9 +16,9 @@ SELECT
) AS "hash_code_columns",
$md5Function(
COALESCE(
(SELECT string_agg(
con.conname || ':' || con.contype::text,
',' ORDER BY con.conname
(SELECT $typeAggFunc(
con.conname || ':' || con.contype::text
$hashConstraintAggTail
)
FROM pg_catalog.pg_constraint con
WHERE con.conrelid = c.oid),

View File

@@ -4,9 +4,9 @@ SELECT
c.relname AS "pure_name",
$md5Function(
COALESCE(
(SELECT string_agg(
a.attname || ':' || pg_catalog.format_type(a.atttypid, a.atttypmod) || ':' || a.attnotnull::text,
',' ORDER BY a.attnum
(SELECT $typeAggFunc(
a.attname || ':' || pg_catalog.format_type(a.atttypid, a.atttypmod) || ':' || a.attnotnull::text
$hashColumnAggTail
)
FROM pg_catalog.pg_attribute a
WHERE a.attrelid = c.oid AND a.attnum > 0 AND NOT a.attisdropped),
@@ -15,9 +15,9 @@ SELECT
) AS "hash_code_columns",
$md5Function(
COALESCE(
(SELECT string_agg(
con.conname || ':' || con.contype::text,
',' ORDER BY con.conname
(SELECT $typeAggFunc(
con.conname || ':' || con.contype::text
$hashConstraintAggTail
)
FROM pg_catalog.pg_constraint con
WHERE con.conrelid = c.oid),