1. Michael Bayer
  2. alembic
  3. Issues

Issues

Issue #109 resolved

Issue with quoting in column rename on MSSQL

Anonymous created an issue

I have a revision file where I call the following operation to fix a casing typo in a column name:

op.alter_column('WLB_SSL_Subledger', 'wlbPremiumDrCR',
                new_column_name='wlbPremiumDrCr',)

The generated SQL is basically

EXEC sp_rename '[WLB_SSL_Subledger].[wlbPremiumDrCR]', '[wlbPremiumDrCr]', 'COLUMN';

But then the renamed column is named [wlbPremiumDrCr] (including the brackets!), i.e., the rename statement should be

EXEC sp_rename '[WLB_SSL_Subledger].[wlbPremiumDrCR]', 'wlbPremiumDrCr', 'COLUMN';

(without brackets).

Comments (4)

  1. Michael Bayer repo owner

    this is annoying, but some experimentation has shown that the "new col name" doesn't need to be quoted, which is why '[name]' is interepreted as two levels of quoting. This works and would be much easier:

    EXEC sp_rename '[WLB_SSL_Subledger].[wlbPremiumDrCR]', [wlbPremiumDrCr], 'COLUMN';
    

    if the name isn't a quotable, then there's no quotes (also seems to work):

    EXEC sp_rename '[WLB_SSL_Subledger].[wlbPremiumDrCR]', some_regular_name, 'COLUMN';
    
  2. Log in to comment