1

My model in Go is:

type Sales_Daily_db struct {
    Nation_shipping string
    Date             datatypes.Date
    Impressions      int `gorm:"type:integer;"`
    Clicks           int `gorm:"type:integer;"`
    Cost             float32
    ATB              float32
    OKL              float32
}

When running AutoMigrate() using the above model, I want the impressions and clicks columns in pSQL database to be of type integer. However, even with those gorm tags, they still ended up as type int4. I have tried int2 int4 int8 manually with the tags above, and they all worked accordingly. Additionally, when I try int tag, they are forced into int8. How to fix this behavior and get integer type specifially in pSQL?

Edit: I am using DBeaver to look at the database.

1
  • 1
    integer is an alias for int4 in Postgres - both are exactly the same thing. Commented Aug 10, 2022 at 6:20

1 Answer 1

2

According to PostgreSQL documentation, this is stated:

SQL only specifies the integer types integer (or int), smallint, and bigint.  
The type names int2, int4, and int8 are extensions, which are also used by some other SQL database systems.

You should be fine with int, integer, smallint and bigint. Anything beyond that is just aliases.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.