pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feed[pgjdbc/pgjdbc] issue #3729: PgDatabaseMetaData.getColumns returns duplicate columnNames
4+ messages / 3 participants
[nested] [flat]
* [pgjdbc/pgjdbc] issue #3729: PgDatabaseMetaData.getColumns returns duplicate columnNames
@ 2025-07-18 01:31 "Chitrae92 (@Chitrae92)" <[email protected]>
0 siblings, 0 replies; 4+ messages in thread
From: Chitrae92 (@Chitrae92) @ 2025-07-18 01:31 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Postgres jdbc version - **42.6.1**
Java version - 17
When we execute code to retrieve column names for a table with schema name having _ in them and there exists similar table in another schema, we currently get duplicate columns due to the like clause used in getColumns
Example:
**Schema Name:** test_ **Table Name:** tableA *Column Names* c1, c2
**Schema Name:** test1 **Table Name:** tableA *Column Names* c1, c2
PgDatabaseMetaData.getColumns function ends up returning c1, c2, c1, c2 when getting the column Names for test_.tableA since the LIKE clause satisfies for both the schema names. Is this expected by design? Should we not escape _ in schema or table names instead of treating them as wild characters.
if (schemaPattern != null && !schemaPattern.isEmpty()) {
sql += " AND n.nspname LIKE " + escapeQuotes(schemaPattern);
}
if (tableNamePattern != null && !tableNamePattern.isEmpty()) {
sql += " AND c.relname LIKE " + escapeQuotes(tableNamePattern);
}
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3729: PgDatabaseMetaData.getColumns returns duplicate columnNames
@ 2025-07-18 09:37 "davecramer (@davecramer)" <[email protected]>
2 siblings, 0 replies; 4+ messages in thread
From: davecramer (@davecramer) @ 2025-07-18 09:37 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
good call, yes, we should escape the _
Feel free to send in a PR
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3729: PgDatabaseMetaData.getColumns returns duplicate columnNames
@ 2025-07-18 10:06 "vlsi (@vlsi)" <[email protected]>
2 siblings, 0 replies; 4+ messages in thread
From: vlsi (@vlsi) @ 2025-07-18 10:06 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
pgjdbc should not escape `_` here.
`java.sql.DatabaseMetaData#getColumns` intentionally uses **patterns** for the parameter names, and it refers to `java.sql.DatabaseMetaData#getSearchStringEscape`.
So the resolution is that end-users should escape the pattern characters like `_` and `%` with a help of `getSearchStringEscape`.
See https://www.postgrespro.com/list/thread-id/1937525
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3729: PgDatabaseMetaData.getColumns returns duplicate columnNames
@ 2025-07-18 10:10 "davecramer (@davecramer)" <[email protected]>
2 siblings, 0 replies; 4+ messages in thread
From: davecramer (@davecramer) @ 2025-07-18 10:10 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
@vlsi Thanks for catching that.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2025-07-18 10:10 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-07-18 01:31 [pgjdbc/pgjdbc] issue #3729: PgDatabaseMetaData.getColumns returns duplicate columnNames "Chitrae92 (@Chitrae92)" <[email protected]>
2025-07-18 09:37 ` "davecramer (@davecramer)" <[email protected]>
2025-07-18 10:06 ` "vlsi (@vlsi)" <[email protected]>
2025-07-18 10:10 ` "davecramer (@davecramer)" <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox