Alternate SELECT statements for different distinct data types

The database server chooses the built-in equals() function when you explicitly cast the arguments. If you modify the SELECT statement as follows, the database server can invoke the equals(int,int) function, and the comparison succeeds:
SELECT * FROM test WHERE p::INT = s::INT;
You can also write and register the following additional functions to allow the SQL user to use the SELECT statement that Sample distinct type invocation shows:
  • An overloaded function equals(pounds,stones) to handle the two distinct data types:
    CREATE FUNCTION equals(pounds, stones) ...

    The advantage of creating an overloaded equals() function is that the SQL user does not need to know that these are new data types that require explicitly casting.

  • Implicit cast functions from the data type pounds to stones and from stones to INT:
    CREATE IMPLICIT CAST (pounds AS stones);
    CREATE IMPLICIT CAST (stones AS INT);