PostgreSQLã§æååã«ã©ã ããæ°å¤åã«ã©ã ã¸å¤æ´ãã
ä»ã¾ã§VARCHARã§æã£ã¦ãããã¼ã¿ããæ°å¤ããå ¥ããªãã£ã¦ãã¨ã§INTEGERåã«å¤ãããã¨ã«ãªã£ããã ãã©ãALTER TABLEããã¾ããããªãã¦ãããããªã
ALTER TABLE foo ALTER COLUMN bar TYPE INTEGER;
ä½ã®èããç¡ãã«ãã£ã¦ã¿ããæ¡ã®å®ã¨ã©ã¼ã«ãªã£ãã
ããããæååãå
¥ã£ã¦ãã®ã«æ°å¤åã«ã¯ã§ããªãããªãã人éããè¦ãã°æ°åããå
¥ã£ã¦ãªããã ãã©ãã
ã¤ã¼ããã§ããªããæ¹æ³ããã ãã¨æã£ã¦ããã¥ã¢ã«è¦ãããUSINGå¥ã¨ããã®ã使ãã°ããããããã¨ãããã£ãã
ããã§å¤æè¦åãæå®ãã¦ãããããã
ãã ããPostgreSQLã®ããã¥ã¢ã«ã®ä¾ã¯ãããã«ããã
USINGå¥ã使ç¨ãã¦ãUnixã¿ã¤ã ã¹ã¿ã³ããæã¤integeråã®åãtimestamp with time zoneã«å¤æ´ãã¾ããALTER TABLE foo ALTER COLUMN foo_timestamp TYPE timestamp with time zone USING timestamp with time zone 'epoch' + foo_timestamp * interval '1 second';ï¼from 日本PostgreSQLユーザ会 | 日本PostgreSQLユーザ会ï¼
ããããããã®ã§ãç´æã«å¾ã£ã¦ãã£ã¦ã¿ãã
ALTER TABLE foo ALTER COLUMN bar TYPE INTEGER USING to_number(bar, 'S9999999999');
ALTER TABLE foo ALTER COLUMN bar TYPE INTEGER USING CAST(bar AS INTEGER);
ã§ããï¼(ã»âã»)
ä¸ä¸ã好ã¿ã®æ¹ã§ã©ããã