1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PostgreSQLにTINYINTは存在しない

Posted at

概要

今までLaravel + MySQLを主に使ってきて最近Laravel + PosgreSQLを使っている。どうやらPosgreSQLにTINYINT型が存在しないらしく勝手に衝撃を受けたのでまとめておく。

PostgreSQLにTINYINTは存在しない

上記をみて驚いた。MySQLのようにTINYINTがあると思ってた。最小がSMALLINTで±32767の間の数値が格納可能らしい。
更にいうとUNSIGNED(符号なし)もないらしい。

PostgraSQL使ってるときにマイグレーションでtinyIntとかを指定したらどうなるの?

SMALLINTに勝手に変換されてカラム定義される。
もちろんいくらマイグレーション側でunsignedTinyIntとか指定しても符号ありのSMALLINTのカラムができる。
なのでマイグレーションだけをみて「unsignedTinyIntだから最大値255だな」とか思わない方がいい。なれないうちはちゃんとDBを見に行ってデータ型を確認したほうがいい。

参考までにMySQLの整数型の値範囲の参考リンクを載せておく。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?