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
Meta.ddl() generates broken DDL for columns of unknown types #15303
Comments
Thanks for your report. We currently don't support that vendor specific type. While it would be possible to support it: A more likely solution to be implemented soon is this data type registry for custom data types and translations: There's no short term solution to this right now. As a workaround / hack, you can create "support" for this type by instantiating your own |
Thank you for your answer. Got it. But could we simply save the name of the type to keep the exported DDL valid? If I am not mistaken, something similar has been done with the DDL of complex views - #15236 |
I see what you mean. It's not the same thing as #15236, where we don't parse an entire view if there's a single problem with its contents, but we still try to get column and data type information separately. Here, we would simply maintain the data type obtained from JDBC, whatever that is. Please note that it might not be reliable at all, i.e. a |
Hmm, never mind. The This works: create table x (i _point);
insert into x values (array['(1, 1)'::point]) |
I just tried this test: @Test
public void testPostgresMetaVendorSpecificTypes() throws Exception {
try {
// [#15303] The ParserCoverageListener parses all rendered SQL, thus registering the
// point data type as a new DefaultDataType, making the test pass for the
// wrong reasons.
System.setProperty("org.jooq.test.parser-coverage-listener", "false");
create().execute("create table t (c point)");
create().execute("insert into t values ('(1, 1)')");
assertEquals("(1.0,1.0)", create().fetchValue("select c from t").toString());
Queries queries =
create().meta()
.filterSchemas(s -> s.getName().equals(schema().getName()))
.filterTables(t -> t.getName().equals("t"))
.ddl(new DDLExportConfiguration().flags(DDLFlag.TABLE));
create().execute("drop table t");
println(queries).executeBatch();
create().execute("insert into t values ('(1, 1)')");
assertThrows(DataAccessException.class, () -> create().execute("insert into t values ('not a point')"));
}
finally {
System.setProperty("org.jooq.test.parser-coverage-listener", "true");
ignoreThrows(() -> create().execute("drop table t"));
}
} It kept passing, because we have some instrumentation that tries to increase the test coverage of the parser like this: static class ParserCoverageListener implements ExecuteListener {
@Override
public void renderEnd(ExecuteContext ctx) {
if (!Boolean.parseBoolean(System.getProperty("org.jooq.test.pretty-printer", "true")))
return;
if (!Boolean.parseBoolean(System.getProperty("org.jooq.test.parser-coverage-listener", "true")))
return;
if (ctx.sql() != null) {
try {
ctx.configuration()
.deriveSettings(s -> s.withParseDialect(ctx.dialect()))
.dsl()
.parser()
.parse(ctx.sql());
}
catch (Exception e) {
PARSE_EXCEPTIONS.putIfAbsent(ctx.sql(), e);
}
}
};
} That made sure the test never failed, because the data type was parsed and instanciated with So, again, as a workaround, you could just initialise all data types from |
With the fix, the above now generates: create table "public"."t" (
"c" point
); I'm reluctant to backport this fix to patch releases. Users may have implemented assumptions based on the type being Given the workarounds, I think it's acceptable to release this only in jOOQ 3.19, as an "incompatible change" |
It's great, thank you. |
Implemented in jOOQ 3.19.0 |
Note that this won't maintain any lengths, precision, scales or other additional type attributes that jOOQ knows nothing about. For most of these vendor specific data types, that's probably OK |
Expected behavior
We expect that Meta.ddl() exports a valid DDL for a table with tsvector columns:
Actual behavior
Meta.ddl() exports broken DDL for that tables:
Steps to reproduce the problem
Create a table in DB:
Run this code:
Executing the resulting query against a different database or schema:
leads to the error:
jOOQ Version
jOOQ Professional Edition 3.18.4
Database product and version
PostgreSQL 15.2 (Debian 15.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
Java Version
openjdk 17.0.2 2022-01-18
OS Version
Microsoft Windows [Version 10.0.19044.2846]
JDBC driver name and version (include name if unofficial driver)
org.postgresql:postgresql:42.6.0
The text was updated successfully, but these errors were encountered: