generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
When creating table with boolean type, the boolean type was converted to NUMBER(1) column in DB instead of BOOLEAN type.
For the following test
type BooleanBasicModel struct {
ID uint `gorm:"primaryKey;autoIncrement"`
Flag bool
Nullable sql.NullBool
CreatedAt time.Time
UpdatedAt time.Time
}
func setupBooleanTestTables(t *testing.T) {
t.Log("Setting up Boolean test tables")
_ = DB.Migrator().DropTable(&BooleanBasicModel{})
if err := DB.AutoMigrate(&BooleanBasicModel{}); err != nil {
t.Fatalf("Failed to migrate BooleanBasicModel: %v", err)
}
}
func TestBooleanBasicInsert(t *testing.T) {
setupBooleanTestTables(t)
// Insert a TRUE record with non-null Nullable=true
trueRecord := &BooleanBasicModel{
Flag: true,
Nullable: sql.NullBool{Bool: true, Valid: true},
}
if err := DB.Create(trueRecord).Error; err != nil {
t.Fatalf("Failed to insert TRUE record: %v", err)
}
if trueRecord.ID == 0 {
t.Fatal("Expected auto-generated ID for TRUE record")
}
}
The generated create table and insert SQLs are:
2025/10/28 22:59:43 /scratch/shulili/GORM/gorm-github/gorm-oracle/oracle/migrator.go:208
[13.729ms] [rows:0] CREATE TABLE "boolean_basic_models" ("id" NUMBER(20) GENERATED BY DEFAULT AS IDENTITY,"flag" NUMBER(1),"nullable" NUMBER(1),"created_at" TIMESTAMP WITH TIME ZONE,"updated_at" TIMESTAMP WITH TIME ZONE,PRIMARY KEY ("id"))
2025/10/28 22:59:43 /scratch/shulili/GORM/gorm-github/gorm-oracle/tests/boolean_test.go:35
[5.443ms] [rows:1] INSERT INTO "boolean_basic_models" ("flag","nullable","created_at","updated_at") VALUES (1,true,'2025-10-28 22:59:43.369','2025-10-28 22:59:43.369') RETURNING "id" INTO 1
The boolean type columns are created as NUMBER column in the database. I think it should create BOOLEAN columns as well because BOOLEAN type is supported in 23.26. So the generated SQLs should be:
CREATE TABLE "boolean_basic_models" ("id" NUMBER(20) GENERATED BY DEFAULT AS IDENTITY,"flag" BOOLEAN,"nullable" BOOLEAN,"created_at" TIMESTAMP WITH TIME ZONE,"updated_at" TIMESTAMP WITH TIME ZONE,PRIMARY KEY ("id"))
INSERT INTO "boolean_basic_models" ("flag","nullable","created_at","updated_at") VALUES (true,true,'2025-10-28 22:59:43.369','2025-10-28 22:59:43.369') RETURNING "id" INTO 1
The above SQLs could work well in 23.26 using sqlplus:
$ sqlplus scott/tiger@inst1
SQL*Plus: Release 23.26.1.0.0 - for Oracle Cloud and Engineered Systems on Tue Oct 28 23:07:57 2025
Version 23.26.1.0.0
Copyright (c) 1982, 2025, Oracle. All rights reserved.
Last Successful login time: Tue Oct 28 2025 22:59:42 +00:00
Connected to:
Oracle AI Database 26ai Enterprise Edition Release 23.26.1.0.0 - for Oracle Cloud and Engineered Systems
Version 23.26.1.0.0
SQL> CREATE TABLE "boolean_basic_models" ("id" NUMBER(20) GENERATED BY DEFAULT AS IDENTITY,"flag" BOOLEAN,"nullable" BOOLEAN,"created_at" TIMESTAMP WITH TIME ZONE,"updated_at" TIMESTAMP WITH TIME ZONE,PRIMARY KEY ("id"));
Table created.
SQL> INSERT INTO "boolean_basic_models" ("flag","nullable") VALUES (true,true);
1 row created.
SQL> desc "boolean_basic_models";
Name Null? Type
----------------------------------------- -------- ----------------------------
id NOT NULL NUMBER(20)
flag BOOLEAN
nullable BOOLEAN
created_at TIMESTAMP(6) WITH TIME ZONE
updated_at TIMESTAMP(6) WITH TIME ZONE
SQL> select * from "boolean_basic_models";
id flag nullable created_at updated_at
---------- ---------- ---------- ---------- ----------
1 TRUE TRUE
SQL>
Metadata
Metadata
Assignees
Labels
No labels