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

insert using select that has a non string column #365

Open
shreyaspurohit opened this issue Aug 2, 2023 · 0 comments
Open

insert using select that has a non string column #365

shreyaspurohit opened this issue Aug 2, 2023 · 0 comments

Comments

@shreyaspurohit
Copy link

Hello,

DB Fiddle for the example: https://www.db-fiddle.com/f/wpNmAGWfjWoZS4goc8EWfc/0

I was trying to generate a SQL like -

INSERT INTO test(id, data_id, type, deleted_at)
SELECT 10, data_id, type, deleted_at
FROM test
WHERE id=7

using -

                 sourceID:=7
                 targetID:=10
		sql, args, err := sb.Insert("test").
			Columns("id", "data_id", "type", "deleted_at").
			Select(
				sb.Select(targetID, "data_id", "type", "deleted_at").From("test")
					Where(squirrel.Eq{
						"id": sourceID,
					}),
			).
			ToSql()

when I realized that the select column needs to be of string type. Is there a way to generate this query where select is having a non string value. Or is there some other way to handle this use case?

Thank you for any help!

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

1 participant