Send netdisco-users mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.sourceforge.net/lists/listinfo/netdisco-users
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of netdisco-users digest..."
Today's Topics:
1. custom_fields (Jon Gerdes)
2. Re: custom_fields (Jon Gerdes)
3. Re: custom_fields (Oliver Gorwits)
--- Begin Message ---
Dear all
I have added a custom_field called oldlocation. I'd like to copy the current
location field into oldlocation and then
change the location field to match the first three characters of the name.
I can see the data with:
netdisco=# select name,location,custom_fields from device;
but I get a bit bogged down with the JSONB notation. My best effort has
yielded lots of these: {"oldlocation": null}
which isn't quite what I'm after.
Could someone help me out with the psql notation please?
Cheers
Jon
--- End Message ---
--- Begin Message ---
On Thu, 2023-01-12 at 18:05 +0000, Jon Gerdes wrote:
> Dear all
>
> I have added a custom_field called oldlocation. I'd like to copy the current
> location field into oldlocation and then
> change the location field to match the first three characters of the name.
>
> I can see the data with:
>
> netdisco=# select name,location,custom_fields from device;
>
> but I get a bit bogged down with the JSONB notation. My best effort has
> yielded lots of these: {"oldlocation": null}
> which isn't quite what I'm after.
>
> Could someone help me out with the psql notation please?
>
> Cheers
> Jon
I'm on my way at last!
netdisco=# UPDATE device SET custom_fields = json_build_object('oldlocation',
location);
That's a Stackoverflow scrape effort (sorry) ...
The next bit should be easy 8)
Cheers
Jon
--- End Message ---
--- Begin Message ---
Hi Jon
Possibly jsonb_set will be more robust as it just updates the oldlocation
field, whereas json_build_object will blow away and replace the whole
custom_fields. Depends if you want to reuse the code and/or have other
custom fields. Below also does some useful and safety type conversions.
UPDATE device
SET custom_fields = jsonb_set(custom_fields, '{oldlocation}'::text[],
to_jsonb(location)),
location = left(name, 3);
Also, thanks for using the custom fields feature! I was very happy to
implement it :-).
regards
oliver.
On Thu, 12 Jan 2023 at 19:48, Jon Gerdes <[email protected]> wrote:
> On Thu, 2023-01-12 at 18:05 +0000, Jon Gerdes wrote:
> > Dear all
> >
> > I have added a custom_field called oldlocation. I'd like to copy the
> current location field into oldlocation and then
> > change the location field to match the first three characters of the
> name.
> >
> > I can see the data with:
> >
> > netdisco=# select name,location,custom_fields from device;
> >
> > but I get a bit bogged down with the JSONB notation. My best effort has
> yielded lots of these: {"oldlocation": null}
> > which isn't quite what I'm after.
> >
> > Could someone help me out with the psql notation please?
> >
> > Cheers
> > Jon
>
> I'm on my way at last!
>
> netdisco=# UPDATE device SET custom_fields =
> json_build_object('oldlocation', location);
>
> That's a Stackoverflow scrape effort (sorry) ...
>
> The next bit should be easy 8)
>
> Cheers
> Jon
>
> _______________________________________________
> Netdisco mailing list
> [email protected]
> https://sourceforge.net/p/netdisco/mailman/netdisco-users/
--- End Message ---
_______________________________________________
Netdisco mailing list - Digest Mode
[email protected]
https://lists.sourceforge.net/lists/listinfo/netdisco-users