0

I'm having a hard time searching to find which databases support the non-standard CAST operator that postgres defines which allows for doing something like:

SELECT '01-OCT-2015'::DATE

I know it's supported in Postgres, but was having a hard time searching google or others to find things like ":: cast". Do any other engines support this?

David542
  • 104,438
  • 178
  • 489
  • 842
  • From here [CAST Syntax](https://www.postgresql.org/docs/14/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS): "The CAST syntax conforms to SQL; the syntax with :: is historical PostgreSQL usage.". So, Postgres only. – Adrian Klaver Aug 01 '22 at 00:07
  • @AdrianKlaver right, but a lot of databases are influenced by or even directly dervied from Postgres, so for example, [Redshift](https://docs.aws.amazon.com/redshift/latest/dg/r_CAST_function.html) or [DuckDB](https://duckdb.org/docs/sql/expressions/cast) or [CockroachDB](https://kb.objectrocket.com/cockroachdb/understanding-the-cockroachdb-cast-function-1535#:~:text=The%20CockroachDB%20CAST%20function%20can,it%20will%20return%20an%20error.) have it, probably many others too... – David542 Aug 01 '22 at 01:40
  • Why not use a SQL standard compliant syntax: `date '2015-10-01'`? –  Aug 01 '22 at 05:31
  • Because AFAIK this `CAST ( expression AS type )` is the SQL standard. From here [CASTS](https://www.postgresql.org/docs/14/sql-expressions.html#SQL-SYNTAX-TYPE-CASTS): `typename ( expression )` "By convention, these conversion functions have the same name as their output type, and thus the “function-like syntax” is nothing more than a direct invocation of the underlying conversion function. Obviously, this is not something that a portable application should rely on." – Adrian Klaver Aug 01 '22 at 15:21

0 Answers0