sql - Renaming column to previously existing column with different type won't let me update -
background: in java application i'm working on, i'm doing refactoring of storage of enum values. previously, these stored integers, , mapped through enum values helper method in enum. utilize @enumtype.string capabilities of jpa make database more readable.
so, i'm trying change type (as values) of column. example, had table definition begin with:
table ( id int, source int, [more columns] ) i wanted change source-column varchar(100) column instead, , here how did that:
- introduce new column, called source_new varchar(100).
- populate new column mapped values based on values of old column (so each row value 1 in source column get's value 'somesource' in source_new, each row value 2 in source gets 'othersource', , on
- drop source-column
- rename source_new column source (using sp_rename)
my problem this: once done, can't update newly defined source-column, because still insists it's int column, , not varchar column!
so query this:
update set source = 'somesource' id = 1; fails this:
error: conversion failed when converting varchar value 'somesource' data type int. sqlstate: 22018 errorcode: 245 at same time, sp_help of table shows column defined varchar(100), , not int! also, column holds numerous varchar values original datamigration (from before rename).
is bug, or doing wrong renaming column column name used type? (and i'm typing last question, sounds absurd me, when drop column expect disappear, not leave traces , in effect not allowing me reuse column name @ time in future..)
sqlfiddle illustrate (sp_rename doesn't work sqlfiddle seems): http://sqlfiddle.com/#!3/0380f/3
i have found culprit, , it's name trigger!
some genious decided put check if value updated valid source (checking against table) in trigger, trusting own code..
i spit on shadow of people hide functionality in database triggers, pfoy! go 80's belong! :p
Comments
Post a Comment