Skip to content

Fix insertion of default values#206

Merged
shane-circuithub merged 1 commit intomasterfrom
fix-insert-default
Oct 17, 2022
Merged

Fix insertion of default values#206
shane-circuithub merged 1 commit intomasterfrom
fix-insert-default

Conversation

@shane-circuithub
Copy link
Copy Markdown
Contributor

@shane-circuithub shane-circuithub commented Oct 17, 2022

At some point, possibly due to a change in Opaleye, insertion of default values (using unsafeDefault) stopped working in Rel8.

In general, PostgreSQL only allows insertion of default values in insert statements that have the form INSERT INTO table VALUES (DEFAULT). The way Opaleye typically generates SQL, the Rel8 equivalent to that code would come out looking more like INSERT INTO table SELECT * FROM (VALUES (DEFAULT)) q. Because the VALUES is wrapped in a SELECT, the DEFAULT becomes invalud PostgreSQL syntax.

To get around this, we special case VALUES when generating SQL for INSERT statements. However, something in the Opaleye representation changed and this special case was no longer firing. This commit fixes that.

At some point, possibly due to a change in Opaleye, insertion of default values (using `unsafeDefault`) stopped working in Rel8.

In general, PostgreSQL only allows insertion of default values in insert statements that have the form `INSERT INTO table VALUES (DEFAULT)`. The way Opaleye typically SQL, the Rel8 equivalent to that code would come out looking more like `INSERT INTO table SELECT * FROM (VALUES (DEFAULT)) q`. Because the `VALUES` is wrapped in a `SELECT`, the `DEFAULT` becomes invalud PostgreSQL syntax.

To get around this, we special case `VALUES` when generating SQL for INSERT statements. However, something in the Opaleye representation changed and this special case was no longer firing. This commit fixes that.
@shane-circuithub shane-circuithub merged commit 5eb5689 into master Oct 17, 2022
@shane-circuithub shane-circuithub deleted the fix-insert-default branch October 17, 2022 10:04
@istathar
Copy link
Copy Markdown

Any chance of cutting a 1.4.0.1 release with this fix in it?

@ocharles
Copy link
Copy Markdown
Contributor

@istathar Yessir. Working on it in #226

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.

3 participants