Brightlane's product catalog import delivers prices as plain text rather than numbers, which breaks downstream pricing calculations. The text value '199.99' needs to be returned as a numeric value.
Write a query to convert it.
Output:
- A single row with one column,
unit_price, typed as numeric.
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
'199.99'::NUMERIC AS unit_price The shape
The ::numeric cast converts the quoted price into a real number that downstream pricing calculations can multiply, add, and compare. Without it the value sits in the database as text that happens to look like a price.
Clause by clause
SELECT '199.99'::numericreads the string literal'199.99'and casts it to anumericvalue. PostgreSQL parses the digits and the decimal point on the left side and produces the number199.99on the right. The::operator is the shorthand cast; the type name on the right is what PostgreSQL converts the value into.AS unit_pricelabels the output column so the result reads as the business field. Without the alias, PostgreSQL would call the columnnumeric, which leaks the implementation type into the result and tells the next person reading it nothing about what the value represents.
The trap
Leave the cast off and the value comes back as text. '199.99' * 12 fails with a type-mismatch error because PostgreSQL won't multiply a string by an integer. Even a comparison like price > 100 either errors or, worse, falls back to lexicographic string comparison where '199.99' is "greater than" '1000.00' because '1' is '1' and '9' comes after '0'. The cast is the boundary between text data and arithmetic; everything past it depends on the value being a real number.
You practiced casting text to a numeric type. Source data often arrives as strings even when the values are numeric — the cast lets the rest of the pipeline treat them as math.