@@ -120,6 +120,7 @@ WITH new_chars AS (
120120 position,
121121 general_type,
122122 column_type,
123+ db_data_type,
123124 functional_data_type,
124125 run_date
125126 FROM {SOURCE_TABLE}
@@ -130,8 +131,9 @@ update_chars AS (
130131 SET ordinal_position = n .position ,
131132 general_type = n .general_type ,
132133 column_type = n .column_type ,
134+ db_data_type = n .db_data_type ,
133135 functional_data_type = COALESCE(n .functional_data_type , d .functional_data_type ),
134- last_mod_date = CASE WHEN n .column_type <> d .column_type THEN n .run_date ELSE d .last_mod_date END,
136+ last_mod_date = CASE WHEN n .db_data_type <> d .db_data_type THEN n .run_date ELSE d .last_mod_date END,
135137 drop_date = NULL
136138 FROM new_chars n
137139 INNER JOIN data_column_chars d ON (
@@ -142,22 +144,22 @@ update_chars AS (
142144 )
143145 WHERE data_column_chars .table_id = d .table_id
144146 AND data_column_chars .column_name = d .column_name
145- RETURNING data_column_chars.* , d .column_type as old_column_type
147+ RETURNING data_column_chars.* , d .db_data_type as old_data_type
146148)
147149INSERT INTO data_structure_log (
148150 element_id,
149151 change_date,
150152 change,
151- old_column_type ,
152- new_column_type
153+ old_data_type ,
154+ new_data_type
153155)
154156SELECT u .column_id ,
155157 u .last_mod_date ,
156158 ' M' ,
157- u .old_column_type ,
158- u .column_type
159+ u .old_data_type ,
160+ u .db_data_type
159161 FROM update_chars u
160- WHERE u .old_column_type <> u .column_type ;
162+ WHERE u .old_data_type <> u .db_data_type ;
161163
162164
163165-- Add new records
@@ -169,6 +171,7 @@ WITH new_chars AS (
169171 position,
170172 general_type,
171173 column_type,
174+ db_data_type,
172175 functional_data_type,
173176 run_date
174177 FROM {SOURCE_TABLE}
@@ -184,6 +187,7 @@ inserted_records AS (
184187 ordinal_position,
185188 general_type,
186189 column_type,
190+ db_data_type,
187191 functional_data_type,
188192 add_date,
189193 last_mod_date
@@ -196,6 +200,7 @@ inserted_records AS (
196200 n .position ,
197201 n .general_type ,
198202 n .column_type ,
203+ n .db_data_type ,
199204 n .functional_data_type ,
200205 n .run_date ,
201206 n .run_date
@@ -218,12 +223,12 @@ INSERT INTO data_structure_log (
218223 element_id,
219224 change_date,
220225 change,
221- new_column_type
226+ new_data_type
222227)
223228SELECT i .column_id ,
224229 i .add_date ,
225230 ' A' ,
226- i .column_type
231+ i .db_data_type
227232 FROM inserted_records i;
228233
229234-- Mark dropped records
@@ -263,10 +268,10 @@ INSERT INTO data_structure_log (
263268 element_id,
264269 change_date,
265270 change,
266- old_column_type
271+ old_data_type
267272)
268273SELECT del .column_id ,
269274 del .drop_date ,
270275 ' D' ,
271- del .column_type
276+ del .db_data_type
272277 FROM deleted_records del;
0 commit comments