Description
Describe the bug
On execution of an INSERT that inserts 1 row, one of the TEXT columns has an empty string value even though a non-empty string was passed in.
Environment (please complete the following information):
- OS: macosx, M2, Mac OS 15.2
- Database: postgres
- Database driver: sql.DB
- Jet version 2.7.1
Code snippet
The table has the following schema:
Column | Type | Collation | Nullable | Default
------------------+---------------------------------+-----------+----------+----------------------------------------
uuid | uuid | | not null |
text_col_1 | text | | not null |
text_col_2 | text | | not null |
created_at | timestamp without time zone | | not null | (now() AT TIME ZONE 'utc'::text)
modified_at | timestamp without time zone | | not null | (now() AT TIME ZONE 'utc'::text)
go-jet generated table:
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
// values obfuscated
var JetTable = newJetTable("abc", "123", "")
type jetTable struct {
postgres.Table
// Columns
UUID postgres.ColumnString
TextCol1 postgres.ColumnString
TextCol2 postgres.ColumnString
CreatedAt postgres.ColumnTimestamp
ModifiedAt postgres.ColumnTimestamp
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type JetTable struct {
jetTable
EXCLUDED jetTable
}
// ... omitting AS, WITH, etc. definitions as they aren't used in this scenario
// newJetTable creates a new JetTable instance with a given schema, table name, and alias.
func newJetTable(schemaName, tableName, alias string) *JetTable {
return &JetTable{
jetTable: newJetTableImpl(schemaName, tableName, alias),
EXCLUDED: newJetTableImpl("", "excluded", ""),
}
}
// newJetTableImpl initializes the underlying jetTable struct.
func newJetTableImpl(schemaName, tableName, alias string) jetTable {
var (
UUIDColumn = postgres.StringColumn("uuid")
TextCol1Column = postgres.StringColumn("text_col_1")
TextCol2Column = postgres.StringColumn("text_col_2")
CreatedAtColumn = postgres.TimestampColumn("created_at")
ModifiedAtColumn = postgres.TimestampColumn("modified_at")
allColumns = postgres.ColumnList{
UUIDColumn, TextCol1Column, TextCol2Column,
CreatedAtColumn, ModifiedAtColumn,
}
mutableColumns = postgres.ColumnList{
TextCol1Column, TextCol2Column, CreatedAtColumn, ModifiedAtColumn,
}
)
return jetTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
// Columns
UUID: UUIDColumn,
TextCol1: TextCol1Column,
TextCol2: TextCol2Column,
CreatedAt: CreatedAtColumn,
ModifiedAt: ModifiedAtColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}
I insert a row like such, where textCol1
and textCol2
had values asdf
and some-value
toInsert := model.RowModel{
UUID: uuid.New(),
TextCol1: textCol1,
TextCol2: textCol2,
}
stmt := jetTable.INSERT(
jetTable.UUID,
jetTable.TextCol1,
jetTable.TextCol2,
).
MODEL(toInsert).
RETURNING(jetTable.AllColumns)
I execute and get the result of the Insert:
dest := model.RowModel{}
err = stmt.QueryContext(ctx, db, &dest)
if err != nil {
return model.RowModel{}, err
}
In the resulting dest
struct, all fields are set correctly except for TextCol1. The TextCol1 value is an empty string, even though a non-empty string was passed into it. I ran a select query on the saved row, and the value was still empty so it seems like it was saved into the DB incorrectly.
Some details:
- Confirmed that the string argument value was non-empty in the query by validating the
stmt.Query()
string returned - Running the equivalent statement using raw sql.DB via query string does not have this issue so it seems like we can rule out some misconfiguration with the db/table
Expected behavior
Expected behavior is that all values are returned as inserted.
Very strange that all other columns are fine except this one column.