[#886] Regression in date extract function when used in a subselect
This commit is contained in:
parent
78b7adb55a
commit
d7336adc01
@ -4950,6 +4950,39 @@ public abstract class jOOQAbstractTest<
|
||||
(record.getValue(tomorrow).getTime() / 1000 - record.getValue(ts).getTime() / 1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExtractInSubselect() throws Exception {
|
||||
Field<Timestamp> now = create().currentTimestamp();
|
||||
|
||||
Field<Integer> year = now.extract(DatePart.YEAR).as("y");
|
||||
Field<Integer> month = now.extract(DatePart.MONTH).as("m");
|
||||
Field<Integer> day = now.extract(DatePart.DAY).as("d");
|
||||
|
||||
Select<?> sub = create().select(year, month, day);
|
||||
Table<?> subTable = sub.asTable("subselect");
|
||||
|
||||
Record reference = sub.fetchOne();
|
||||
Record result;
|
||||
|
||||
result = create().select().from(sub).fetchOne();
|
||||
assertEquals(reference, result);
|
||||
|
||||
result = create().select().from(subTable).fetchOne();
|
||||
assertEquals(reference, result);
|
||||
|
||||
result = create().select(
|
||||
sub.getField("y"),
|
||||
sub.getField("m"),
|
||||
sub.getField("d")).from(sub).fetchOne();
|
||||
assertEquals(reference, result);
|
||||
|
||||
result = create().select(
|
||||
subTable.getField("y"),
|
||||
subTable.getField("m"),
|
||||
subTable.getField("d")).from(subTable).fetchOne();
|
||||
assertEquals(reference, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFunctionsOnNumbers() throws Exception {
|
||||
|
||||
|
||||
@ -122,16 +122,14 @@ abstract class AbstractSelect<R extends Record> extends AbstractResultQuery<R> i
|
||||
|
||||
@Override
|
||||
public final Table<R> asTable() {
|
||||
Table<R> table = new SelectQueryAsTable<R>(this);
|
||||
|
||||
// Its usually better to alias nested selects that are used in
|
||||
// the FROM clause of a query
|
||||
return table.as("alias_" + Math.abs(table.hashCode()));
|
||||
return new SelectQueryAsTable<R>(this).as("alias_" + Math.abs(hashCode()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Table<R> asTable(String alias) {
|
||||
return asTable().as(alias);
|
||||
return new SelectQueryAsTable<R>(this).as(alias);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -67,13 +67,6 @@ class Extract extends AbstractFunction<Integer> {
|
||||
@Override
|
||||
final Field<Integer> getFunction0(Configuration configuration) {
|
||||
switch (configuration.getDialect()) {
|
||||
case INGRES: // No break
|
||||
case MYSQL: // No break
|
||||
case POSTGRES: // No break
|
||||
case HSQLDB: // No break
|
||||
case H2:
|
||||
return new SQLExtract();
|
||||
|
||||
case SQLITE:
|
||||
switch (datePart) {
|
||||
case YEAR:
|
||||
@ -149,8 +142,15 @@ class Extract extends AbstractFunction<Integer> {
|
||||
throw new SQLDialectNotSupportedException("DatePart not supported: " + datePart);
|
||||
}
|
||||
|
||||
case INGRES: // No break
|
||||
case MYSQL: // No break
|
||||
case POSTGRES: // No break
|
||||
case HSQLDB: // No break
|
||||
case H2:
|
||||
|
||||
// A default implementation is necessary for hashCode() and toString()
|
||||
default:
|
||||
throw new SQLDialectNotSupportedException("extract not supported");
|
||||
return new SQLExtract();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user