ITADN
go-pg/pg/Issues

Valid struct fields getting ignored

#2036OpenpWoLiAn 创建于 2025-11-15
P
pWoLiAncommented
<!--- Provide a general summary of the issue in the Title above --> ``` package main import ( "context" "log" "github.com/go-pg/pg/v10" "github.com/go-pg/pg/v10/orm" ) type TestStruct struct { Foo string `pg:"bar,pk"` Bar string `pg:"-"` } func main() { db := pg.Connect(&pg.Options{ Addr: "localhost:30892", User: "dbUser", Password: "dbPassword", Database: "postgres", }) defer db.Close() // Enable query logging to see what SQL is generated db.AddQueryHook(queryLogger{}) // Create table err := db.Model((*TestStruct)(nil)).CreateTable(&orm.CreateTableOptions{ Temp: true, }) if err != nil { log.Printf("Create table error: %v", err) } // Try to insert test := &TestStruct{Foo: "value1", Bar: "value2"} _, err = db.Model(test).Insert() if err != nil { log.Printf("Insert error: %v", err) } } // Query logger to see generated SQL type queryLogger struct{} func (q queryLogger) BeforeQuery(ctx context.Context, event *pg.QueryEvent) (context.Context, error) { query, err := event.FormattedQuery() log.Printf("SQL: %s", query) return ctx, err } func (q queryLogger) AfterQuery(ctx context.Context, event *pg.QueryEvent) error { return nil } ``` ## Expected Behavior 2025/11/15 17:18:10 SQL: CREATE TEMP TABLE "test_structs" ("bar" text, PRIMARY KEY ("bar")) 2025/11/15 17:18:10 SQL: INSERT INTO "test_structs" ("bar") VALUES ('value1') <!--- Tell us what should happen --> ## Current Behavior 2025/11/15 17:17:23 SQL: CREATE TEMP TABLE "test_structs" () 2025/11/15 17:17:23 SQL: INSERT INTO "test_structs" () VALUES () 2025/11/15 17:17:23 Insert error: ERROR #42601 syntax error at or near ")" <!--- Tell us what happens instead of the expected behavior -->
0 条评论