Re: cast bytea to macaddr

From: Matt Zagrabelny <mzagrabe(at)d(dot)umn(dot)edu>
To: Boris Zentner <bzm(at)2bz(dot)de>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: cast bytea to macaddr
Date: 2023-09-28 18:24:08
Message-ID: CAOLfK3VZQc-oCRY-3YYQuhyHUtN7cGp4PP-9GKSi4jYjiBEABQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Boris,

[bringing this email back to the mailing list]

A couple of questions:

1. What do the double parenthesis '(( Values .... ))' mean?

2. What is the 'x(field)' in the column alias?

Thanks for educating me!

-m

On Thu, Sep 28, 2023 at 10:34 AM Boris Zentner <bzm(at)2bz(dot)de> wrote:

> Hi matt,
>
> This is my take. I guess this is also your solution ( encode(fteld,
> 'hex'): :macaddr )
>
> SELECT encode(fteld, 'hex'): :macaddr FROM ((VALUES
> (decode('aabbccddeeff', 'hex'))))
>
> AS x(field)
> --
> Boris
>
>
> Am 28.09.2023 um 17:01 schrieb Matt Zagrabelny <mzagrabe(at)d(dot)umn(dot)edu>:
>
> 
> 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
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raivo Rebane 2023-09-28 18:51:14 Right version of jdbc
Previous Message Dave Cramer 2023-09-28 16:50:35 Re: Right version of jdbc