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

Decompose a structure array into one-dimensional arrays #2234

Closed
igkg opened this issue Jan 17, 2025 · 3 comments
Closed

Decompose a structure array into one-dimensional arrays #2234

igkg opened this issue Jan 17, 2025 · 3 comments

Comments

@igkg
Copy link

igkg commented Jan 17, 2025

This article talks about the advantages of passing one-dimensional arrays and combining them on the PG side via unnest. But it is inconvenient to collect one-dimensional arrays on the application side. It is convenient to put them into a structure and then put it into an array. Is it possible to come up with something to easily get single arrays for passing from an array of structures? Or pass an array of structures to the pgx driver function, and it will cut it into single arrays itself.

@jackc
Copy link
Owner

jackc commented Jan 25, 2025

In most cases, COPY should be preferred as it provides the best performance. If COPY cannot be used, such as when ON CONFLICT is needed then pgx's batch functionality should be preferred as that works with ON CONFLICT and provides feedback about what happened to each row.

It is unusual that this array / unnest pattern is the optimal approach and it's unlikely pgx will include helpers for this specific use case.

@jackc jackc closed this as completed Jan 25, 2025
@igkg
Copy link
Author

igkg commented Jan 25, 2025

@jackc
It is not just about inserting, it also makes sense for updating, merging and deleting from select + unnest.

@igkg
Copy link
Author

igkg commented Jan 26, 2025

It turns out that they already tried to push this through at the compiler level. Oh, how much usefulness would come out of it.

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

2 participants