Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgres query serialized yaml field

I have a field in a database that is serialized (sadly) into Yaml.

Below is the field definition on the table:

  class Account < Sequel::Model
    include ModelManager

    plugin :serialization

    serialize_attributes :yaml, :billing_info

I would really like to transform this into the new json type but we are still on postgres 9.2.6.

Is there anyway that I can query this data until I can migrate it?

The field either contains an empty definition like this:

--- !ruby/object:BillingInfo {}

Or has data like this:

--- !ruby/object:BillingInfo
gateway_identifier: blah 
organisation: blah
billing_email: blah
reference: blah
phone: blah
country: blah
vat: blah
subscription: blah
like image 801
dagda1 Avatar asked Aug 04 '26 10:08

dagda1


1 Answers

If you mean query at the PostgreSQL level, you'll have to add your own yaml parser, using something like plv8 and js-yaml as explained here:

Store and index YAML with PostgreSQL, with Javascript lib or reusable functions?

like image 182
Jeremy Evans Avatar answered Aug 07 '26 16:08

Jeremy Evans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!