doug-martin / goqu

SQL builder and query library for golang
http://doug-martin.github.io/goqu/
MIT License
2.37k stars 207 forks source link

Insertion Query for []Text result in the wrong query on postgres dialect #387

Open confusionhill opened 1 year ago

confusionhill commented 1 year ago

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:

Additional context Add any other context about the problem here.

myusko commented 1 year ago

@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.

LeeSaferite commented 4 months ago

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