Skip to content

Implement FromSql for tuples up to length 4 #626

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

benesch
Copy link
Contributor

@benesch benesch commented Jul 2, 2020

This makes it very ergonomic to decode the results of a query like

SELECT (1, 'a')

where (1, 'a') is returned as an anonymous record type.

The big downside to this approach is that only built-in OIDs are
supported, as there is no way to know ahead of time what OIDs will be
returned, and so we'll only have metadata for the built-in OIDs lying
around.

Fix #310. Also related to #366 and #565.

This makes it very ergonomic to decode the results of a query like

    SELECT (1, 'a')

where (1, 'a') is returned as an anonymous record type.

The big downside to this approach is that only built-in OIDs are
supported, as there is no way to know ahead of time what OIDs will be
returned, and so we'll only have metadata for the built-in OIDs lying
around.
@AtsukiTak
Copy link

Looks great! I'm very interested in this feature!
It would be nice for me if it is also implemented for tuples more than 5 items under some feature gate just like diesel's 32-column-tables, 64-column-tables and 128-column-tables features. 😄

I hope this PR will be merged!

@skreborn
Copy link

@sfackler Is there anything - other than a rebase - that prevents this from being merged? I agree that at least 8 tuple items should be supported, but adding huge numbers seems excessive for a first implementation. We can always add more (behind feature flags) later, building on this PR.

Right now, we're forced to implement this ourselves, and it would help tremendously to have built-in support for tuples.

@WGH-
Copy link

WGH- commented Mar 27, 2022

This is a useful feature.

Maybe not so on its own: who writes SELECT (foo, bar) ... instead of SELECT foo, bar, after all?

But if you do things like SELECT t1, array_agg((t2.foo, t2.bar)) FROM t1 NATURAL JOIN t2 GROUP BY t1.id, support for the record type suddenly becomes much more useful. This example would also require support for the record[] type, but that would be the next step.

wquark added a commit to cubexch/rust-postgres that referenced this pull request Jul 21, 2024
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

Successfully merging this pull request may close these issues.

FromSql for a type Record
4 participants