Part 109: Type Casting & Conversions: CAST and :: Operator

Part 109 Technology Updated September 12, 2026

Part 109: Type Casting & Conversions: CAST and :: Operator

Converting data from one type to another explicitly.


1. ANSI Standard: CAST()

SELECT CAST('2024-05-15' AS DATE) AS event_date;
SELECT CAST(129.99 AS INT) AS truncated_price;

2. PostgreSQL Shorthand: ::

SELECT '123'::INTEGER AS id_num;
SELECT NOW()::DATE AS today;

Key Takeaways

  • Use CAST(val AS TYPE) for standard portability; use ::type in PostgreSQL.

In Part 110, we explore JSON in SQL: Storing, Querying & Indexing JSON/JSONB Data!