Comments (6)
Sorry this is a duplicate issue of my pull request. I thought I had to create an issue first and then associate it to the pull request.
from pgjdbc.
On 07/16/2014 06:49 AM, hiro2k wrote:
The JDBC spec says when you have duplicate columns names, the first one
should be returned but this behavior isn't useful to us. What we really
need is the ability to resolve those ambiguous cases in the client code.
Isn't that what query aliases are for?
SELECT table1.a AS t1a, table2.a AS t2a
FROM ...
I propose adding an additional string to the columnNameIndexMap that
would be in the format of tablename.column similar to how you would
reference the columns in SQL.
That's potentially sensible, but introduces a tricky conflict:
SELECT table1.a, table2."table1.a"
FROM ...
i.e. quoted identifiers may contain anything, including a period. In a
flat map like that there's no way to tell whether you're looking at a
field named "table1.a" or a field named "a" from table "table1".
Probably not a big issue in the real world - we'd just have to give
priority to unqualified identifiers in case of a conflict. Still worth
thinking about.
I've added a test case for this use case that shows that it works and
doesn't affect any existing test cases.
Heh. That mostly shows that our test coverage isn't ideal there.
That said, if the spec permits us to have >1 entry for a given index, I
don't have a big problem with doing what you suggest. I'd like to see a
lot more real-world app testing though.
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
from pgjdbc.
Hi ringerc, thanks for your feedback. You're correct that this is the use case for query aliases but this change helps when doing a rather stupid SELECT * FROM t1, t2, t3 ... and I'm not sure what to do about the quoted identifiers, other than stating that the current behavior is to load the map in reverse order so if it shows up first in the result set it will win and be present in the end.
This came up while I was porting an application from MySQL that has hundreds of those SELECT * queries. It was a big surprise when we found out that wasn't standard behavior in the jdbc spec and only the MySQL driver supported it, but we decided that it would be more work to change all of our queries than patching the postgres driver.
I've been maintaining this patch #172 for a long time, but I figured it would be better to try and get it accepted upstream and share this solution with anyone else trying to port a MySQL app.
from pgjdbc.
On 07/16/2014 10:58 PM, hiro2k wrote:
Hi ringerc, thanks for your feedback. You're correct that this is the
use case for query aliases but this change helps when doing a rather
stupid SELECT * FROM t1, t2, t3 ... and I'm not sure what to do about
the quoted identifiers, other than stating that the current behavior is
to load the map in reverse order so if it shows up first in the result
set it will win and be present in the end.This came up while I was porting an application from MySQL that has
hundreds of those SELECT * queries. It was a big surprise when we found
out that wasn't standard behavior in the jdbc spec and only the MySQL
driver supported it, but we decided that it would be more work to change
all of our queries than patching the postgres driver.I've been maintaining this patch #172
#172 for a long time, but I
figured it would be better to try and get it accepted upstream and share
this solution with anyone else trying to port a MySQL app.
That's a good reason to make such a change, for sure.
I think a good choice here might be to introduce a new parameter like
compatible= or emulate= that tells PgJDBC "try to support things that
this other database's driver does".
So that way we're not adding new params whenever someone wants to add a
corner case / quirk handler for some other DBMS's drivers too.
Thoughts?
I'm not sure how to name it though. I don't want to suggest that people
should expect the driver to emulate the database's syntax etc. We
won't be supporting quotes
or [quotes] any time soon or returning true
for NULL = NULL.
driverpersonality=mysql ?
Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
from pgjdbc.
I don't foresee anybody enabling two compatibility modes at the same time as it makes no sense. Having a single property seems like a good idea. The embedded JDBC database H2 has a similar concept: http://www.h2database.com/html/features.html#compatibility
Couple alternate names to consider:
- drivermode
- compatibilitymode
- drivercompatibilitymode
Given that code that makes use of a property like this would be all over the place, we should make sure that the impact to non-usage isn't more than a boolean branch check.
For example in the case of this patch, putting aside whether it might break existing applications, the number of map insertions in findColumnIndex(...)
doubles. That should be avoided.
from pgjdbc.
I personally think the JDBC driver should stick to the spec rather than adding many vendor-specific flags and modes. As @ringerc mentioned, aliases are the standard way of handling this type of problem.
from pgjdbc.
Related Issues (20)
- capitalization matters for PGInterval HOT 1
- PgStatement.executeWithFlags(sql, QueryMode.Simple) does not execute in Simple mode
- SQLWarnings returned on successful SQL statements HOT 28
- Provide Enum implementation of java.sql.SQLType interface? HOT 1
- Using Flink Datastream API to read and write PostgreSQL
- "ERROR: SET TRANSACTION ISOLATION LEVEL must not be called in a subtransaction" with autosave HOT 2
- SSLSocket duplex close failed (again) HOT 5
- Trying to update table using PreparadStatement, But parameters are generated inside a Parentheses HOT 1
- INSERT Java Boolean Type into a database BIT type will result in an incompatible type error. HOT 5
- Authentication SSL Mechanism HOT 20
- Query interceptors HOT 4
- Authentication failed SSL error HOT 1
- Memory Consumption, binary transfer bug HOT 5
- "Unexpected packet type during copy" when network is pool HOT 2
- Connect Java with PostgreSQL (16.3) using SSPI authentication HOT 3
- Inconsistent SQL execution with "unsupported format code" error in PostgreSQL HOT 8
- Request for new release 42.7.4 HOT 1
- SSL connection is not established HOT 22
- BlobInputStream#mark/reset caches position within a large object, however it should buffer the data instead HOT 3
- JDBC Driver Ignoring Fetch Size: Full SELECT Result Loaded into RAM, Causing Heap Overflow HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pgjdbc.