PostgreSQL – WHERE Clause Converting INT to DATETIME

datedate formatdatetimepostgresql

Looking for advice on how to match two differing column types:

I have two tables: RT-A and DA-B.

Under both tables there is a column named DeliveryDate, but the individual tables use differing column types; one time without timezone and the other numeric.

Example: in the DA-A table the DeliveryDate column reads: "02:00:00"
Example: in the RT-A table the DeliveryDate column reads, "2".

What is the correct expression in the WHERE clause of an SQL statement to join rows where they equal each other?
Plain equality obviously does not work With the current design:

"DA-A"."DeliveryHour" = "RT-A"."DeliveryHour"

This is how I have been writing the SQL, but it seems to be terrible in form:

WHERE
  "DA-A"."DeliveryHour" = '2:00:00' AND 
  "RT-A"."DeliveryHour" = '2'

Best Answer

Referencing Postgres documentation: Date/Time Functions and Operators

How do you like this?

WHERE date_part('hour', "DA-A"."DeliveryHour") = "RT-A"."DeliveryHour"