[#4269] No columns generated for PostgreSQL SETOF [ scalar type ]

This commit is contained in:
lukaseder 2015-05-05 08:36:14 +02:00
parent 8da0229d1b
commit 4ef2b92d3c

View File

@ -42,6 +42,7 @@
package org.jooq.util.postgres;
import static org.jooq.impl.DSL.inline;
import static org.jooq.impl.DSL.nvl;
import static org.jooq.impl.DSL.partitionBy;
import static org.jooq.impl.DSL.row;
import static org.jooq.impl.DSL.rowNumber;
@ -130,23 +131,33 @@ public class PostgresTableValuedFunction extends AbstractTableDefinition {
// table reference is reported via a TYPE_UDT that matches a table
// from INFORMATION_SCHEMA.TABLES
select(
c.COLUMN_NAME,
c.ORDINAL_POSITION,
c.DATA_TYPE,
c.CHARACTER_MAXIMUM_LENGTH,
c.NUMERIC_PRECISION,
c.NUMERIC_SCALE,
c.IS_NULLABLE,
c.COLUMN_DEFAULT,
c.UDT_NAME
nvl(c.COLUMN_NAME , getName() ).as(c.COLUMN_NAME),
nvl(c.ORDINAL_POSITION , 1 ).as(c.ORDINAL_POSITION),
nvl(c.DATA_TYPE , r.DATA_TYPE ).as(c.DATA_TYPE),
nvl(c.CHARACTER_MAXIMUM_LENGTH , r.CHARACTER_MAXIMUM_LENGTH ).as(c.CHARACTER_MAXIMUM_LENGTH),
nvl(c.NUMERIC_PRECISION , r.NUMERIC_PRECISION ).as(c.NUMERIC_PRECISION),
nvl(c.NUMERIC_SCALE , r.NUMERIC_SCALE ).as(c.NUMERIC_SCALE),
nvl(c.IS_NULLABLE , "true" ).as(c.IS_NULLABLE),
nvl(c.COLUMN_DEFAULT , (String) null ).as(c.COLUMN_DEFAULT),
nvl(c.UDT_NAME , r.UDT_NAME ).as(c.UDT_NAME)
)
.from(r)
.join(c).on(row(r.TYPE_UDT_CATALOG, r.TYPE_UDT_SCHEMA, r.TYPE_UDT_NAME)
.eq(c.TABLE_CATALOG, c.TABLE_SCHEMA, c.TABLE_NAME))
// [#4269] SETOF [ scalar type ] routines don't have any corresponding
// entries in INFORMATION_SCHEMA.COLUMNS. Their single result table
// column type is contained in ROUTINES
.leftOuterJoin(c)
.on(row(r.TYPE_UDT_CATALOG, r.TYPE_UDT_SCHEMA, r.TYPE_UDT_NAME)
.eq(c.TABLE_CATALOG, c.TABLE_SCHEMA, c.TABLE_NAME))
.join(pg_n).on(r.SPECIFIC_SCHEMA.eq(pg_n.NSPNAME))
.join(pg_p).on(pg_p.PRONAMESPACE.eq(oid(pg_n)))
.and(pg_p.PRONAME.concat("_").concat(oid(pg_p)).eq(r.SPECIFIC_NAME))
.where(r.SPECIFIC_NAME.eq(specificName))
// [#4269] Exclude TABLE [ some type ] routines from the first UNION ALL subselect
// Can this be done more elegantly?
.and( row(r.SPECIFIC_CATALOG, r.SPECIFIC_SCHEMA, r.SPECIFIC_NAME)
.notIn(select(p.SPECIFIC_CATALOG, p.SPECIFIC_SCHEMA, p.SPECIFIC_NAME).from(p).where(p.PARAMETER_MODE.eq("OUT"))))
.and(pg_p.PRORETSET))
// Either subselect can be ordered by their ORDINAL_POSITION