pgx BYTEA and json.RawMessage confusion #1537
-
I am working with pgx/v5 and have a table in postgres that looks like the below and a following insert statement as well. -- Scheduled Tasks Table
CREATE TABLE IF NOT EXISTS scheduled_tasks (
uuid UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
type_name VARCHAR(255) NOT NULL,
queue_name VARCHAR(255) NOT NULL,
payload BYTEA NOT NULL,
cronspec VARCHAR(255) NOT NULL,
time_zone VARCHAR(255) NOT NULL
); const createScheduledTask = `-- name: CreateScheduledTask :one
INSERT INTO scheduled_tasks (type_name, queue_name, payload, cronspec, time_zone)
VALUES ($1, $2, $3, $4, $5)
RETURNING uuid, type_name, queue_name, payload, cronspec, time_zone
`
type CreateScheduledTaskParams struct {
TypeName string `db:"type_name" json:"type_name"`
QueueName string `db:"queue_name" json:"queue_name"`
Payload []byte `db:"payload" json:"payload"`
Cronspec string `db:"cronspec" json:"cronspec"`
TimeZone string `db:"time_zone" json:"time_zone"`
}
func (q *Queries) CreateScheduledTask(ctx context.Context, arg CreateScheduledTaskParams) (ScheduledTask, error) {
row := q.db.QueryRow(ctx, createScheduledTask,
arg.TypeName,
arg.QueueName,
arg.Payload,
arg.Cronspec,
arg.TimeZone,
)
var i ScheduledTask
err := row.Scan(
&i.UUID,
&i.TypeName,
&i.QueueName,
&i.Payload,
&i.Cronspec,
&i.TimeZone,
)
return i, err
} I then receive a POST request that takes the JSON payload and puts it into a struct like type Task struct {
Task string `json:"task"`
Cronspec string `json:"cronspec"`
Queue string `json:"queue"`
Payload json.RawMessage `json:"payload"`
} However what I am experiencing is when I insert this into the database and then later retrieve it. I receive data that is quoted and base64 encoded Why do I not receive a []byte? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's not clear from you message whether the problem is on insert or on retrieval. If you use psql to inspect the data is it correct int the database? |
Beta Was this translation helpful? Give feedback.
It's not clear from you message whether the problem is on insert or on retrieval. If you use psql to inspect the data is it correct int the database?