Comments (8)
That's unfortunate. Thanks for reporting this, I wasn't aware of this. I may have to check other databases as well. This will be solved in 2.0.1 with ticket #986:
https://sourceforge.net/apps/trac/jooq/ticket/986
from jooq.
Excellent, thanks.
from jooq.
Interestingly, unique key and primary key names cannot be repeated among tables. I wonder why Postgres allows for repeating foreign key names...
from jooq.
The names PostgreSQL itself autogenerates for anonymous foreign key definitions are of the form tablename_columnname_fkey.
However, the database I was originally running jOOQ against was created by a RAD tool which doesn't follow the same conventions.
CREATE TABLE baz2 (
id SERIAL PRIMARY KEY,
c INTEGER
);
CREATE TABLE foo2 (
id SERIAL PRIMARY KEY,
baz2_id INTEGER NOT NULL REFERENCES baz2 (id),
a INTEGER
);
CREATE TABLE bar2 (
id SERIAL PRIMARY KEY,
asdf_id INTEGER NOT NULL REFERENCES baz2 (id),
b INTEGER
);
jooq_fk_testcase=# \d foo2
Table "public.foo2"
Column | Type | Modifiers
---------+---------+---------------------------------------------------
id | integer | not null default nextval('foo2_id_seq'::regclass)
baz2_id | integer | not null
a | integer |
Indexes:
"foo2_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"foo2_baz2_id_fkey" FOREIGN KEY (baz2_id) REFERENCES baz2(id)
jooq_fk_testcase=# \d bar2
Table "public.bar2"
Column | Type | Modifiers
---------+---------+---------------------------------------------------
id | integer | not null default nextval('bar2_id_seq'::regclass)
asdf_id | integer | not null
b | integer |
Indexes:
"bar2_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"bar2_asdf_id_fkey" FOREIGN KEY (asdf_id) REFERENCES baz2(id)
from jooq.
I see. In jOOQ, I have already implemented a similare disambiguation for the Sybase SQL Anywhere database. There, I'm naming key literals [TABLE_NAME]__[KEY_NAME], which works fine with the added test case for #986, also in Postgres. So I'm doing this also for:
- DB2 (allows for reusing PK/UK/FK names)
- Postgres (allows for reusing FK names)
- SQLite (allows for reusing PK/UK/FK names)
- Sybase ASE (allows for reusing PK/UK names)
- Sybase SQL Anywhere (allows for reusing PK/UK/FK names)
These subtle little SQL differences always amaze me...
from jooq.
How about user-defined templates, or template fragments?
I wonder if there is ever going to be a project to systematically document these database peccadilloes, so that the authors of each ORM/database tool don't have to learn each problem through pain, and maintain this knowledge base in their brains?
from jooq.
If by user-defined templates, you mean source code generation through Groovy / Velocity / XSLT / ... scripts, this is a pending feature request:
https://sourceforge.net/apps/trac/jooq/ticket/62
It has also been discussed on the user group before:
https://groups.google.com/forum/#!forum/jooq-user
Already today, you can write your own implementation of org.jooq.util.Generator in Java, if you're missing a feature. Besides that, I was proposed a pull request implementing Groovy templating, which should be ready some time in January (although I can't guarantee that this will be done).
On the other hand, if source code generation is left to the user, you won't profit from the ORM / database tool community, which has already gone through many of these issues.
Apart from that, I'm documenting some of those "peccadilloes" in my blog: http://lukaseder.wordpress.com. I doubt that it's even possible to find a "general" solution to abstract all SQL / JDBC, especially if you want to go as far as jOOQ. The jOOQ codebase is full of dialect-specific SQL generation. So you could also consider jOOQ to be such a piece of documentation :-)
from jooq.
BTW: This issue is fixed on SVN trunk, GitHub and will be contained in the next Maven SNAPSHOT, later today:
https://oss.sonatype.org/content/repositories/snapshots/org/jooq/
from jooq.
Related Issues (20)
- Add support for character set prefixes on string literals
- Visibility when UNotYetImplemented of ContraintImpl will be addressed ?
- Add support for Asterisk and QualifiedAsterisk in GROUP BY
- Update using multi-column set clause with DSL.row and custom type logs warn on deprecated static type registry HOT 1
- Rename SQLDialect.ORACLE23C to ORACLE23AI
- Support CTE column aliasing for plain SQL templates where this isn't supported
- Support newline and separator tokens in plain SQL templates
- Error when running DELETE .. USING .. LIMIT in MySQL HOT 4
- Wrong emulation of DELETE .. USING .. LIMIT where DELETE .. LIMIT is not natively supported HOT 5
- Add broader DELETE .. USING and UPDATE .. FROM support, using the same emulation as that for DML ORDER BY .. LIMIT HOT 2
- HANA UPDATE statement always repeats target table, even if unnecessary HOT 1
- Support references to UPDATE .. FROM tables from SET clause in dialects that don't support MERGE
- Add support for Oracle 23ai enumeration domains
- Let DataAccessException::sqlStateClass be based on HANA error codes for SQLStateClass 22 or 23
- Add HANA support for LATERAL, CROSS APPLY, OUTER APPLY
- Add HANA support for COLLATE HOT 3
- Add HANA support for FOR JSON and FOR XML
- Support FIRST_VALUE and LAST_VALUE as aggregate functions, where possible, as synonyms for MAX_BY and MIN_BY
- Add parser support for SQLite's TOTAL() aggregate function HOT 1
- Add parser support for Teradata's MAXIMUM() and MINIMUM() synonyms for MAX() and MIN()
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 jooq.