PostgreSQL Type Casting (::)
Postgres's own shorthand for CAST — same conversion, more compact syntax.
What & Why
The :: operator is Postgres-specific shorthand for CAST — value::type means exactly the same thing as CAST(value AS type), just shorter to write.
See How It Works
EXAMPLE QUERY
-- these two lines do exactly the same thing
SELECT CAST('55000' AS INTEGER);
SELECT '55000'::INTEGER;RESULT — both return the same value
| expression | result |
|---|---|
| CAST('55000' AS INTEGER) | 55000 |
| '55000'::INTEGER | 55000 |
The result uses the same Queryflo columns shown in the worked example.
Now You Try
Practice this concept
Marketing wants campaign spend rounded to whole-number output using PostgreSQL double-colon casting.
Available schema
marketingPrefix tables with marketing.table_name.
namespendwhole_spendmarketing.campaigns| Column | Type |
|---|---|
| id | integer |
| name | text |
| channel | text |
| spend | numeric |
| start_date | date |
| end_date | date |
| status | text |
| target_segment | text |
| legacy_id | text |
query.sql
Sign up free to try it on a real business scenario