I am new to PostgreSQL and absolutely lost here. (Guess even the title is absolutely wrong...)
I have e.g. this:
postgres=# SELECT round(10000::decimal/100, 4);
round
----------
100.0000
(1 row)
Is there an easy way to get the same result using a custom type:
postgres=# SELECT 10000::my_type;
----------
100.0000
(1 row)
I think it depends on the type. For example, the following works for me on Postgres 9.3
# CREATE TYPE foo AS (num INT);
CREATE TYPE
# SELECT 300::foo;
ERROR: cannot cast type integer to foo
LINE 1: SELECT 300::foo
# SELECT (ROW(300)::foo).num;
num
-----
300
(1 row)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With