Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.35 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Data changes when converting a varchar column to smallint
  2. CREATE TABLE ad_position_ad (
  3.  p_id           bigint                ,
  4.  p_name         character varying(20) ,
  5.  devid          integer               ,
  6.  ad_type        character varying(20) ,
  7.  platform       character varying(20) ,
  8.  category_id    integer               ,
  9.  config         character varying(20) ,
  10.  is_check       character varying(20) ,
  11.  status         character varying(20) ,
  12.  showing_total  bigint                ,
  13.  click_total    bigint                ,
  14.  user_total     bigint                ,
  15.  income_total   bigint                ,
  16.  online_time    integer               ,
  17.  create_time    integer               ,
  18.  modify_time    integer);
  19.        
  20. mydb=> select count(*) from ad_position_ad;
  21.  count
  22. -------
  23.    275
  24. (1 row)
  25.  
  26. mydb=> select distinct config from ad_position_ad;
  27.  config
  28. --------
  29.  2
  30.  0
  31.  1
  32. (3 rows)
  33.        
  34. mydb=>
  35. alter table ad_position_ad
  36. alter column config type smallint using platform::smallint;
  37. ALTER TABLE
  38.        
  39. mydb=> select distinct config from ad_position_ad;
  40.  config
  41. --------
  42.       3
  43. (1 row)
  44.        
  45. mydb=>
  46. alter table ad_position_ad
  47. alter column config type smallint using cast(config as smallint);
  48. ALTER TABLE
  49.        
  50. alter table ad_position_ad
  51. alter column config type smallint using platform::smallint;
  52.        
  53. alter table ad_position_ad
  54. alter column config type smallint using config::smallint;