Learn SQL/Beginner/Data Types & Casting/PostgreSQL Type Casting (::)

PostgreSQL Type Casting (::)

Postgres's own shorthand for CAST — same conversion, more compact syntax.

What & Why

The :: operator is Postgres-specific shorthand for CASTvalue::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
expressionresult
CAST('55000' AS INTEGER)55000
'55000'::INTEGER55000

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
marketing

Prefix tables with marketing.table_name.

namespendwhole_spend
marketing.campaigns
ColumnType
idinteger
nametext
channeltext
spendnumeric
start_datedate
end_datedate
statustext
target_segmenttext
legacy_idtext
query.sql
Beginner business practice

Sign up free to try it on a real business scenario