Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks
confusionhill opened this issue Jul 28, 2023 · 2 comments
Open
2 tasks

Comments

@confusionhill
Copy link

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.

@myusko
Copy link

myusko commented Aug 7, 2023

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants