DEV Community

Daniel Kukula
Daniel Kukula

Posted on

1

TIL: Non standard postgres types in livebook

Livebook has a new, nice feature that allows you to connect to a database. It works with basic data types.

livebook screenshot

But I found a problem when the data type is not supported by postgrex.
livebook screenshot
In this case, you can either have to write a custom postgrex extension like the example here. In postgrex GitHub repo, there are many examples for common data types, but XML is missing there.

You can also cast your field to a supported data type:

SELECT demographics::text from person.person   
Enter fullscreen mode Exit fullscreen mode

livebook screenshot
To play with this example, you can install the example Adventureworks database provided by Microsoft. I made an elixir converter that converts some of the files to a format accepted by PostgreSQL, and also updated the previous version to properly name the columns with underscores.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
thbar profile image
Thibaut Barrère

I met the same situation and ultimately I converted the smart cell for the connection into code, added the types: DB.PostgrexTypes, and earlier defined them with

Postgrex.Types.define(DB.PostgrexTypes, [Geo.PostGIS.Extension], [])
Enter fullscreen mode Exit fullscreen mode

Thanks for your post which put me on track!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay