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

Issue #2217 - PostgreSQL: Insert statement generation breaks for tables that have a column with the same name as the table #2225

Merged
merged 3 commits into from
Aug 16, 2024
Merged
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 @@ -76,7 +76,10 @@ public List<String> genInsertStmt(final Collection<PersistedEntityMetadata<?>> e
// and:
// SELECT * FROM 'TABLE_NAME';
// The source for this stored procedure can be found in tgpsa-dao/src/main/resources/sql/create_insert_statement.sql
try (final PreparedStatement ps = conn.prepareStatement(format("select create_insert_statement(tableoid, %s) from %s", table, table))) {

// Must pass mytable.* to create_insert_statement: if table "mytable" has column named "mytable",
// then "mytable" will refer to the column, not the table.
try (final PreparedStatement ps = conn.prepareStatement("select create_insert_statement(tableoid, %1$s.*) from %1$s".formatted(table))) {
try (final ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
inserts.add(rs.getString(1));
Expand All @@ -97,4 +100,4 @@ public DbVersion dbVersion() {
return DbVersion.POSTGRESQL;
}

}
}