fix: migration 138 use string-concat EXECUTE, no nested dollar-quoting
This commit is contained in:
parent
a33da15550
commit
14b13b8239
@ -2,6 +2,7 @@
|
|||||||
-- Prevents ambiguous mapping during e-conomic sync
|
-- Prevents ambiguous mapping during e-conomic sync
|
||||||
|
|
||||||
-- Normalize values before uniqueness check (only for text-like columns)
|
-- Normalize values before uniqueness check (only for text-like columns)
|
||||||
|
-- Uses string-concatenated EXECUTE to avoid nested dollar-quoting issues
|
||||||
DO $$
|
DO $$
|
||||||
DECLARE
|
DECLARE
|
||||||
column_data_type TEXT;
|
column_data_type TEXT;
|
||||||
@ -13,19 +14,16 @@ BEGIN
|
|||||||
AND table_name = 'customers'
|
AND table_name = 'customers'
|
||||||
AND column_name = 'economic_customer_number';
|
AND column_name = 'economic_customer_number';
|
||||||
|
|
||||||
|
-- Only normalize whitespace for text-type columns (integer columns are skipped)
|
||||||
IF column_data_type IN ('character varying', 'character', 'text') THEN
|
IF column_data_type IN ('character varying', 'character', 'text') THEN
|
||||||
EXECUTE $sql$
|
EXECUTE 'UPDATE customers'
|
||||||
UPDATE customers
|
|| ' SET economic_customer_number = NULL'
|
||||||
SET economic_customer_number = NULL
|
|| ' WHERE economic_customer_number IS NOT NULL'
|
||||||
WHERE economic_customer_number IS NOT NULL
|
|| ' AND btrim(economic_customer_number) = ''''';
|
||||||
AND btrim(economic_customer_number::text) = ''
|
|
||||||
$sql$;
|
|
||||||
|
|
||||||
EXECUTE $sql$
|
EXECUTE 'UPDATE customers'
|
||||||
UPDATE customers
|
|| ' SET economic_customer_number = btrim(economic_customer_number)'
|
||||||
SET economic_customer_number = btrim(economic_customer_number::text)
|
|| ' WHERE economic_customer_number IS NOT NULL';
|
||||||
WHERE economic_customer_number IS NOT NULL
|
|
||||||
$sql$;
|
|
||||||
END IF;
|
END IF;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user