Fix unsupported date_part() in CrDB (#16461)

This commit is contained in:
ian
2022-11-16 04:22:12 +08:00
committed by GitHub
parent adeabdfe7b
commit e79720735a

View File

@@ -10,35 +10,35 @@ const parseLocaltime = (columnType?: string) => {
export class FnHelperPostgres extends FnHelper {
year(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('year', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(YEAR FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
month(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('month', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(MONTH FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
week(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('week', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(WEEK FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
day(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('day', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(DAY FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
weekday(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('dow', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(DOW FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
hour(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('hour', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(HOUR FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
minute(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('minute', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(MINUTE FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
second(table: string, column: string, options: FnHelperOptions): Knex.Raw {
return this.knex.raw(`DATE_PART('second', ??.??${parseLocaltime(options?.type)})`, [table, column]);
return this.knex.raw(`EXTRACT(SECOND FROM ??.??${parseLocaltime(options?.type)})`, [table, column]);
}
count(table: string, column: string, options?: FnHelperOptions): Knex.Raw {