Skip to content

column name in the constraint is not quoted automatically #100

@shelly-li-sl

Description

@shelly-li-sl

When defining a table with a constraint, double quotes are not added for the column name in the constraint.

For this table struct:

      type LaxJSONRecord struct {
           ID  uint           `gorm:"primaryKey;autoIncrement;column:record_id"`
	   Doc datatypes.JSON `gorm:"type:CLOB;column:doc;check:doc_is_json_lax, doc IS JSON(LAX)"`
	}
        DB.Migrator().DropTable(&LaxJSONRecord{})
	if err := DB.Set("gorm:table_options", "TABLESPACE SYSAUX").AutoMigrate(&LaxJSONRecord{}); err != nil {
		t.Fatalf("migrate failed: %v", err)
	}

The generated SQL is:
CREATE TABLE "lax_json_records" ("record_id" NUMBER(20) GENERATED BY DEFAULT AS IDENTITY,"doc" CLOB,PRIMARY KEY ("record_id"),CONSTRAINT "doc_is_json_lax" CHECK (doc IS JSON(LAX)))TABLESPACE SYSAUX

The expected SQL is:
CREATE TABLE "lax_json_records" ("record_id" NUMBER(20) GENERATED BY DEFAULT AS IDENTITY,"doc" CLOB,PRIMARY KEY ("record_id"),CONSTRAINT "doc_is_json_lax" CHECK ("doc" IS JSON(LAX)))TABLESPACE SYSAUX

Double quotes should be added for the column name 'doc' in the constraint

===Test case: TestJSONLAX and TestJSONStrict in json_bulk_2_test.go

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions