# PostgreSQL XML data and Elixir / Ecto?

**URL:** <https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317>\
**Category:** Questions\
**Tags:** ecto, xml\
**Created:** [June 16, 2025, 10:31pm UTC](https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317 "2025-06-16T22:31:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![christhekeele](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/christhekeele/32/1039_2.png) [@christhekeele](https://forum.elixirforum.com/u/christhekeele)\
**Post date:** [June 17, 2025, 4:38am UTC](https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317/2 "2025-06-17T04:38:39Z")

</div>

AFICT, nothing in the ecosystem today ([postgrex](https://hexdocs.pm/postgrex/readme.html#features) nor extensions/peers) supports postgres xml [types](https://www.postgresql.org/docs/current/datatype-xml.html), [functions](https://www.postgresql.org/docs/17/functions-xml.html), or [queries](https://www.postgresql.org/docs/17/xml2.html).

For types, you can use [custom `Ecto.Type`s](https://hexdocs.pm/ecto/Ecto.Type.html) to handle serialization between PG and Elixir. For DDLs, I’d just write my migrations in straight SQL strings, executed by `Repo.query!` rather than a DSL.

For functions and queries, you’re going to want to use [fragments](https://hexdocs.pm/ecto/Ecto.Query.html#module-fragments). Essentially, escaping the pure data-modelling of Ecto to insert raw SQL into an otherwise safely Ecto-built query.

This is similar to what I do in my python projects that use XML columns, and it works fairly well. Our use-case is write-once query-occasionally so it’s fairly trivial: we rarely need to read the full document into memory once inserted, and never need to update it.

More integrated functionality would require more work. Perhaps a library calling out to be made?

---

_[View the full topic](https://forum.elixirforum.com/t/postgresql-xml-data-and-elixir-ecto/71317)._
