cast bytea to macaddr

From: Matt Zagrabelny <mzagrabe(at)d(dot)umn(dot)edu>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: cast bytea to macaddr
Date: 2023-09-28 15:00:36
Message-ID: CAOLfK3V2bPXyGeriAHDvs3T-zYsqqzL9a0DH+DayuZccT_8jSA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Greetings Pg folks,

I have a database schema (not mine) that uses bytea to represent a MAC
address. I'd like to create a view that casts that field into a MACADDR
type.

# \d lease4
Table "public.lease4"
Column │ Type │ Collation │ Nullable │ Default
════════════════╪══════════════════════════╪═══════════╪══════════╪═════════
hwaddr │ bytea │ │ │

# select hwaddr from lease4;
hwaddr
════════════════
\x9cebe803e3b9

It looks like I can cast the bytea to text and then manipulate that and
finally cast it to macaddr.

Is there a better, or more canonical, way to convert/cast this field?

Thanks for any help!

-m

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Mehmet Çakoğlu 2023-09-28 15:19:34 YNT: Need help tuning a query
Previous Message Dave Cramer 2023-09-28 09:32:37 Re: Right version of jdbc