🏠 ホーム
プログラミング
インフラ
フリーランスCTO
DB
完全無料ツールまとめ
マーケティング

integerからtextに間違えて変更したときの対処法 (postgres)

  DB >  

間違えたり、仕様変更で型変換を行う事もあると思います。
全ての値が数字でもtext型であれば普通にtypeは変換できません。

エラーがでました。

update dt_enquete set u_id = pv_u_id

ERROR: column "u_id" is of type integer but expression is of type text
LINE 1: update dt_enquete set u_id = pv_u_id

HINT: You will need to rewrite or cast the expression.

次に無理やり計算したらその結果は数字だと思ったけどまたエラーがでました。

update dt_enquete set u_id = pv_u_id/1

SQL エラー:

ERROR: operator does not exist: text / integer
LINE 1: update dt_enquete set u_id = pv_u_id/1
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.

phpみたいにゆるくないですね(笑。

ぐぐってさがしました。
答え

update dt_enquete set u_id = cast(pv_u_id as int)

登録日:

更新日:

by

コメント         tweetでコメント