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

Fixes 5032 column adjacency for PostgreSql UPDATE FROM statement #5035

Merged
merged 4 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ internal abstract class UpdateStmtLimitedMixin(
FromQuery {
override fun queryAvailable(child: PsiElement): Collection<QueryElement.QueryResult> {
if (child != joinClause && joinClause != null) {
return super.queryAvailable(child) + joinClause!!.queryExposed()
return super.queryAvailable(child) +
joinClause!!.queryExposed().map { it.copy(adjacent = true) }
}

return super.queryAvailable(child)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
CREATE TABLE test(
id SERIAL PRIMARY KEY
id SERIAL PRIMARY KEY,
id2 INTEGER
);

CREATE TABLE test2(
id2 SERIAL PRIMARY KEY
id2 SERIAL PRIMARY KEY,
other TEXT
);

UPDATE test
Expand Down Expand Up @@ -40,4 +42,8 @@ FROM (
ON otherTest.id = test2.id2
);

UPDATE test
SET id2 = t2.id2
FROM test2 t2
WHERE other = 'x';

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE TABLE test(
id SERIAL PRIMARY KEY,
id2 INTEGER
);

CREATE TABLE test2(
id2 SERIAL PRIMARY KEY,
other TEXT
);

insertTest:
INSERT INTO test (id2) VALUES(?);

insertTest2:
INSERT INTO test2 (other) VALUES(?);

updateTestId:
UPDATE test
SET id = t2.id2
FROM (
SELECT
id2
FROM test2
) AS t2 RETURNING test.id;

updateTestId2:
UPDATE test
SET id2 = t2.id2
FROM test2 t2
WHERE other = ? RETURNING test.id2;
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,24 @@ class PostgreSqlTest {
}
}

@Test
fun testUpdateSetFromId() {
database.updatesQueries.insertTest(31)
database.updatesQueries.insertTest2("X")
with(database.updatesQueries.updateTestId().executeAsOne()) {
assertThat(this).isEqualTo(1)
}
}

@Test
fun testUpdateSetFromId2() {
database.updatesQueries.insertTest(31)
database.updatesQueries.insertTest2("X")
with(database.updatesQueries.updateTestId2("X").executeAsOne()) {
assertThat(id2).isEqualTo(1)
}
}

@Test
fun testSelectTsVectorSearch() {
database.textSearchQueries.insertLiteral("the rain in spain")
Expand Down