Lets say I have two tables in Postgres:
Name: table_rad
Column Type
id integer
username character varying(64)
Name: table_mac
Column Type
id integer
mac macaddr
I want to do to a join:
SELECT * FROM table_rad WHERE username = mac;
Postgres will complain:
ERROR: operator does no exist: character varying = macaddr
LINE 1: ...ELECT * from table_rad WHERE username = mac;
^
Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
Sofar I have googled for a solution and I know I have to CAST. But how can I cast type macaddr as varhcar?
Formal style: CAST(mac AS varchar)
PostgreSQL-style: mac::varchar
e.g.:
SELECT * FROM table_rad JOIN table_mac ON username = CAST(mac AS varchar)
You can do it by ::text like below:
SELECT * FROM table_rad WHERE username = mac::text;
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