Insertion Query for []Text result in the wrong query on postgres dialect
confusionhill opened this issue · 2 comments
Describe the bug
I'm currently trying to insert a list of email into my database, but the query that It produce does not complies to what postgres expected. Are there any issue or perhaps what i do is wrong? Thanks
To Reproduce
If applicable provide a small code snippet to reproduce the issue:
db entity :
type TeamEntity struct {
TeamID string `db:"team_id"`
TeamName string `db:"team_name"`
TeamLeaderID string `db:"team_leader_id"`
BuktiPembayaranURL string `db:"bukti_pembayaran_url"`
IsVerified bool `db:"is_verified"`
TeamMemberMails []string `db:"team_member_mails"`
IsActive bool `db:"is_active"`
}
query builder :
q := r.qb.Insert("teams").
Rows(goqu.Record{
"team_name": newTeam.TeamName,
"team_leader_id": newTeam.TeamLeaderID,
"bukti_pembayaran_url": newTeam.BuktiPembayaranURL,
"team_member_mails": newTeam.TeamMemberMails,
})
query result
INSERT INTO "teams" ("bukti_pembayaran_url", "team_leader_id", "team_member_mails", "team_name") VALUES ('', '0e824030-fc43-43ac-a80d-bdd3fd42c25d', ('email@email.com', 'maama@mama.co', 'email@notemail.com'), 'tim jekatah')
Expected behavior
A clear and concise description of what you expected to happen.
expected query
INSERT INTO "teams" ("bukti_pembayaran_url", "team_leader_id", "team_member_mails", "team_name")
VALUES ('', '0e824030-fc43-43ac-a80d-bdd3fd42c25d', '{"email@email.com", "maama@mama.co", "email@notemail.com"}', 'tim jekatah');
the difference are withing the list of emails
Dialect:
- [v ] postgres
- mysql
- sqlite3
Additional context
Add any other context about the problem here.
@doug-martin Hey, if it's a bug, I'd be happy to work on it.
Also, if it's a bug, I'd appreciate any links/tips on a code that I need to take a look at the start point.
I know this ticket is quite old at this point, but I've run into the same issue as well. The conversion of a slice into an array in Postgres is either broken or obscure enough that I've been unable to find how to do so.
The code responsible for generation the invalid Postgres arrays is here: https://github.com/doug-martin/goqu/blob/master/sqlgen/expression_sql_generator.go#L369-L378