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

Columns don't expand properly in INSERT SELECT statements #769

Open
baileywickham opened this issue Jan 5, 2024 · 0 comments
Open

Columns don't expand properly in INSERT SELECT statements #769

baileywickham opened this issue Jan 5, 2024 · 0 comments

Comments

@baileywickham
Copy link

In this case, ${uniqueColumns} should be a list of columns to insert data from the select statement but the generated sql statement uses the values syntax.

Typescript:

const uniqueColumns = ['uniqueId']
await sql`INSERT INTO "schema".${stagingRelation} ${uniqueColumns}
		SELECT ${uniqueColumns} FROM "schema".${dataRelation} 
		WHERE col IN ${sql(col)} ON CONFLICT DO NOTHING`;

Generated SQL statement:

INSERT INTO "schema"."table_staging" ("0","1","2","3","4","5","6","7")values($1,$2,$3,$4,$5,$6,$7,$8) SELECT "uniqueId" FROM "schema"."table" WHERE col IN ($9,$10,$11) ON CONFLICT DO NOTHING

Best I can tell this is caused by this line of code. Let me know if there is anything I can do to 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