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
|
||||
|
||||
-- Normalize values before uniqueness check (only for text-like columns)
|
||||
-- Uses string-concatenated EXECUTE to avoid nested dollar-quoting issues
|
||||
DO $$
|
||||
DECLARE
|
||||
column_data_type TEXT;
|
||||
@ -13,19 +14,16 @@ BEGIN
|
||||
AND table_name = 'customers'
|
||||
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
|
||||
EXECUTE $sql$
|
||||
UPDATE customers
|
||||
SET economic_customer_number = NULL
|
||||
WHERE economic_customer_number IS NOT NULL
|
||||
AND btrim(economic_customer_number::text) = ''
|
||||
$sql$;
|
||||
EXECUTE 'UPDATE customers'
|
||||
|| ' SET economic_customer_number = NULL'
|
||||
|| ' WHERE economic_customer_number IS NOT NULL'
|
||||
|| ' AND btrim(economic_customer_number) = ''''';
|
||||
|
||||
EXECUTE $sql$
|
||||
UPDATE customers
|
||||
SET economic_customer_number = btrim(economic_customer_number::text)
|
||||
WHERE economic_customer_number IS NOT NULL
|
||||
$sql$;
|
||||
EXECUTE 'UPDATE customers'
|
||||
|| ' SET economic_customer_number = btrim(economic_customer_number)'
|
||||
|| ' WHERE economic_customer_number IS NOT NULL';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user