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

Support INSERT statement over SQL adapter #7462

Merged
merged 26 commits into from
Jul 18, 2024
Merged

Support INSERT statement over SQL adapter #7462

merged 26 commits into from
Jul 18, 2024

Conversation

aljazerzen
Copy link
Contributor

@aljazerzen aljazerzen commented Jun 14, 2024

Todo and general implementation strategy tracked in #7294

@aljazerzen aljazerzen changed the title sql insert Support INSERT statement over SQL adapter Jun 14, 2024
@aljazerzen aljazerzen marked this pull request as draft June 14, 2024 17:01
@aljazerzen
Copy link
Contributor Author

This PR is getting big, so I think it is better to merge what's done and iterate later. But it being big is not the only reason: I'm not confident with the general approach so I think it is ready to be reviewed.

There is still a few minor questions open, see TODO comments.

But stuff now generally works, including the hard thing that is multiple DML stmts, passing values between them.

The other hard thing (link tables) is left to do.

@aljazerzen aljazerzen marked this pull request as ready for review July 5, 2024 12:43
@aljazerzen aljazerzen requested a review from msullivan July 5, 2024 12:43
Copy link
Member

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

Great work!

Could you make a list of all the TODOs and put it in the issue?

Comment on lines +637 to +640
if is_link:
val_col_pg = pgast.TypeCast(
arg=val_col_pg, type_name=pgast.TypeName(name=('uuid',))
)
Copy link
Member

Choose a reason for hiding this comment

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

Huh, why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To produce a better error when users are trying to insert non-uuids into link columns.

For example:

edgedb=# INSERT INTO "Document" (owner_id) VALUES (4);
ERROR:  cannot cast type integer to uuid
LINE 1: INSERT INTO "Document" (owner_id) VALUES (4);
        ^

Not great, but better than talking about "operator = not existing for uuid and integer".


if not res_query.ctes:
res_query.ctes = []
res_query.ctes.extend(pg_res_rel.extract_ctes_from_ctx(ctx))
Copy link
Member

Choose a reason for hiding this comment

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

Do these ctes wind up nested then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. extract_ctes_from_ctx returns a list of ctes, but only when ctx is top-level.

This is here to achieve exactly the opposite: have all generated CTEs at the top-level.

@aljazerzen aljazerzen merged commit f8de70f into master Jul 18, 2024
23 checks passed
@aljazerzen aljazerzen deleted the sql-insert branch July 18, 2024 16:08
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.

2 participants