Class PostgreSQLRDBMSWeekdayOfDateTimeFunction

java.lang.Object
com.kingsrook.qqq.backend.module.postgres.fieldfunctions.PostgreSQLRDBMSWeekdayOfDateTimeFunction
All Implemented Interfaces:
BackendFieldFunctionAdapterInterface, RDBMSFieldFunctionAdapterInterface, Serializable

public class PostgreSQLRDBMSWeekdayOfDateTimeFunction extends Object implements RDBMSFieldFunctionAdapterInterface
PostgreSQL adapter for the WeekdayOfDateTimeFunction that generates EXTRACT(ISODOW FROM (col AT TIME ZONE 'UTC') AT TIME ZONE ?) SQL expressions.

QQQ stores datetime values as UTC in TIMESTAMP (no-tz) columns. PostgreSQL's single-argument AT TIME ZONE on a TIMESTAMP interprets the stored value as if it were already in the named zone, which would be wrong here. The two-step form first declares the stored value to be UTC (producing a TIMESTAMPTZ), then converts that TIMESTAMPTZ to the target zone. This matches the behaviour of CONVERT_TZ in MySQL.

PostgreSQL's ISODOW matches ISO-8601 (Monday=1 … Sunday=7), so no numeric offset is needed.

See Also:
  • Constructor Details

    • PostgreSQLRDBMSWeekdayOfDateTimeFunction

      public PostgreSQLRDBMSWeekdayOfDateTimeFunction()
  • Method Details

    • wrapColumnName

      public String wrapColumnName(String escapedColumnName, FieldFunction fieldFunction, Function<String,String> fieldNameToColumnReference)
      Returns a EXTRACT(ISODOW FROM (col AT TIME ZONE 'UTC') AT TIME ZONE ?) expression. The single bind parameter (target timezone) is supplied by getParams(com.kingsrook.qqq.backend.core.model.metadata.fields.functions.FieldFunction). The two-step AT TIME ZONE is required because QQQ stores datetimes as UTC in TIMESTAMP (without time zone) columns: the first step declares the stored value to be UTC; the second step converts it to the target zone.
      Specified by:
      wrapColumnName in interface RDBMSFieldFunctionAdapterInterface
      Parameters:
      escapedColumnName - a fully qualified and escaped SQL column name for the 'main' field that this function works with (e.g., FieldFunction#withFieldName(String). Looks like: `my_table`.`my_field`.
      fieldFunction - the function with arguments, being used.
      fieldNameToColumnReference - resolves a QQQ field name to its fully- qualified escaped SQL column reference (e.g., "timeZone"`t1`.`time_zone`). Useful when the function expression needs to reference additional columns on the same row.
    • getParams

      public List<Serializable> getParams(FieldFunction fieldFunction)
      Returns the single bind parameter: the resolved target timezone (session, instance default, or explicit override).
      Specified by:
      getParams in interface RDBMSFieldFunctionAdapterInterface
    • wrapColumnNameForOrderBy

      public String wrapColumnNameForOrderBy(String escapedColumnName, FieldFunction fieldFunction, Function<String,String> fieldNameToColumnReference)
      Returns the ORDER BY expression using the same two-step AT TIME ZONE form. When sortSundayFirst is true, appends % 7 so Sunday (value 7) sorts as 0 before Monday.
      Specified by:
      wrapColumnNameForOrderBy in interface RDBMSFieldFunctionAdapterInterface