|
| 1 | +SET SEARCH_PATH TO {SCHEMA_NAME}; |
| 2 | + |
| 3 | +-- Schema-name matching in the SQL Server DDF query is now case-sensitive, |
| 4 | +-- consistent with TestGen's case-sensitive joins and the other flavors. |
| 5 | +-- A case-insensitive source previously accepted a table |
| 6 | +-- group whose configured schema name differed in case from the database; |
| 7 | +-- such a group would now match no tables on its next profiling run. |
| 8 | +-- |
| 9 | +-- data_table_chars.schema_name holds the case the source database actually |
| 10 | +-- reported (it is populated from the DDF's c.table_schema, not the entered |
| 11 | +-- value), so realign table_group_schema to that case. Guards: |
| 12 | +-- * only mssql connections -- the DDF change was made only for that flavor, |
| 13 | +-- * only when the catalog reports a single unambiguous schema for the group, |
| 14 | +-- * only a case-only difference (LOWER() match), never a different schema, |
| 15 | +-- * '<>' is case-sensitive in PostgreSQL, so correct rows are left untouched. |
| 16 | +-- After this, the group's next profiling run stamps profile_results with the |
| 17 | +-- corrected case, realigning the case-sensitive downstream joins. |
| 18 | +UPDATE table_groups tg |
| 19 | +SET table_group_schema = actual.schema_name |
| 20 | +FROM ( |
| 21 | + SELECT table_groups_id, MIN(schema_name) AS schema_name |
| 22 | + FROM data_table_chars |
| 23 | + WHERE drop_date IS NULL |
| 24 | + GROUP BY table_groups_id |
| 25 | + HAVING COUNT(DISTINCT schema_name) = 1 |
| 26 | +) actual |
| 27 | +WHERE actual.table_groups_id = tg.id |
| 28 | + AND tg.table_group_schema <> actual.schema_name |
| 29 | + AND LOWER(tg.table_group_schema) = LOWER(actual.schema_name) |
| 30 | + AND EXISTS ( |
| 31 | + SELECT 1 FROM connections cn |
| 32 | + WHERE cn.connection_id = tg.connection_id |
| 33 | + AND cn.sql_flavor = 'mssql' |
| 34 | + ); |
0 commit comments