Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL TinyInteger (tinyint) does not exist as a type #204

Closed
nickb937 opened this issue Dec 10, 2021 · 1 comment · Fixed by #207
Closed

PostgreSQL TinyInteger (tinyint) does not exist as a type #204

nickb937 opened this issue Dec 10, 2021 · 1 comment · Fixed by #207
Assignees

Comments

@nickb937
Copy link

As far as I can tell, the type tinyint, or 1-byte integer, does not exist for PostgreSQL: https://www.postgresql.org/docs/14/datatype-numeric.html

I suppose one solution is to define the column with a CHECK constraint, but it would cause hassle around forcing into a i8/u8 type:

room_bed_count SMALLINT CHECK (room_bed_count >=-128 && room_bed_count <= 127)

SeaORM definition:

impl ColumnTrait for Column {
    type EntityName = Entity;

    fn def(&self) -> ColumnDef {
        match self {
            Self::RoomId => ColumnType::BigInteger.def(),
            Self::RoomTag => ColumnType::String(Some(64)).def(),
            Self::RoomLocation => ColumnType::String(Some(32)).def().nullable(),
            Self::RoomType => ColumnType::String(Some(32)).def().nullable(),
            Self::RoomTypeOther => ColumnType::String(Some(32)).def().nullable(),
            Self::RoomRate => ColumnType::Decimal(Some((8, 2))).def().nullable(),
            Self::RoomRateUnit => ColumnType::String(Some(16)).def().nullable(),
            Self::RoomBedCount => ColumnType::TinyInteger.def(),
        }
    }
}

Resulting statement:

CREATE TABLE "asset_room" ( "room_id" bigserial NOT NULL PRIMARY KEY, "room_tag" varchar(64) NOT NULL, "room_location" varchar(32), "room_type" varchar(32), "room_type_other" varchar(32), "room_rate" decimal(8, 2), "room_rate_unit" varchar(16), "room_bed_count" tinyint NOT NULL );

Resulting psql error:

ERROR:  type "tinyint" does not exist
LINE 1: ...), "room_rate_unit" varchar(16), "room_bed_count" tinyint NO...
@billy1624
Copy link
Member

billy1624 commented Dec 16, 2021

Hey @nickb937, sorry for the delay.

For now, I will map ColumnType::TinyInteger to smallint

ColumnType::TinyInteger(length) => match length {
Some(length) => format!("tinyint({})", length),
None => "tinyint".into(),
},

REF: https://www.postgresql.org/docs/current/datatype.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants