Skip to content

feat(postgres): add copyfrom support - #92

Open
kellen-miller wants to merge 5 commits into
sqlc-dev:mainfrom
kellen-miller:add-copyfrom
Open

feat(postgres): add copyfrom support#92
kellen-miller wants to merge 5 commits into
sqlc-dev:mainfrom
kellen-miller:add-copyfrom

Conversation

@kellen-miller

@kellen-millerkellen-miller commented Aug 23, 2025

Copy link
Copy Markdown

Closes#63

@kellen-millerkellen-miller changed the title Add copyfromAdd :copyfrom supportAug 23, 2025

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements support for the :copyfrom command in sqlc-gen-python, enabling efficient bulk insert operations. The implementation leverages SQLAlchemy's executemany behavior by passing lists of parameter dictionaries to Connection.execute().

Key Changes:

  • Added :copyfrom command support with automatic handling of both struct and non-struct parameters
  • Removed the previous error that blocked CopyFrom usage
  • Added comprehensive test coverage and examples demonstrating both sync and async usage

Reviewed changes

Copilot reviewed 44 out of 45 changed files in this pull request and generated 1 comment.

Show a summary per file
FileDescription
internal/gen.goCore implementation: adds BuildCopyFromBody, addCopyFromArgs, and buildStructToDictList methods; removes CopyFrom error; adds switch cases for :copyfrom in sync/async queriers
internal/imports.goAdds import logic for typing.List and typing.Any types needed by copyfrom methods
internal/endtoend/testdata/copyfrom/*New end-to-end test case with schema, queries, and expected generated code covering multiple copyfrom scenarios
examples/src/authors/query.sqlAdds example CreateAuthorsBatch copyfrom query
examples/src/authors/query.pyGenerated code demonstrating copyfrom method with List[Any] parameter
examples/src/tests/test_authors.pyTest cases validating both sync and async copyfrom functionality
README.mdDocumentation explaining copyfrom usage with examples for both List[Any] and typed struct parameters
internal/endtoend/testdata/*/sqlc.yamlUpdated sha256 hashes for new WASM binary version
internal/endtoend/testdata//python/.pyUpdated generated file version comments from v1.28.0 to v1.29.0
.gitignoreAdds .idea/ IDE directory to gitignore

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadinternal/gen.go
Comment on lines +251 to +254
body = append(body, assignNode(targetVar, poet.Node(&pyast.Call{
Func: poet.Name("list"),
Args: []*pyast.Node{},
})))

CopilotAINov 24, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using list() to create an empty list is less efficient than using a list literal []. In Python, [] is more idiomatic and has better performance since it doesn't require a function call. Consider updating the code generation to use [] instead of list().

Copilot uses AI. Check for mistakes.

@kellen-millerkellen-millerDec 3, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure if the custom AST/printer that generates the python supports [] without adding a new node/printing logic. It currently emits list() for empty lists so I’ve left list() for now. Happy to change if the generator can do literals though.

@kellen-millerkellen-miller changed the title Add :copyfrom supportfeat: add pg copyfrom supportMar 26, 2026
@kellen-millerkellen-miller changed the title feat: add pg copyfrom supportfeat(postgres): add copyfrom supportMar 26, 2026
@devstein

Copy link
Copy Markdown
Collaborator

Hey @kellen-miller - will try take a look at this soon. Feel free to ping me if you don't get a review in the next week or so!

@kellen-miller

Copy link
Copy Markdown
Author

Hey @devstein have you had a chance to review this pr?

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support copyfrom

3 participants

@kellen-miller@devstein