# :erlang.term\_to\_binary and postgresql =\> invalid byte sequence for encoding "UTF8"

**URL:** <https://forum.elixirforum.com/t/erlang-term-to-binary-and-postgresql-invalid-byte-sequence-for-encoding-utf8/59862>\
**Category:** Questions\
**Tags:** ecto\
**Created:** [November 21, 2023, 6:49am UTC](https://forum.elixirforum.com/t/erlang-term-to-binary-and-postgresql-invalid-byte-sequence-for-encoding-utf8/59862 "2023-11-21T06:49:09Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jhogberg](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/32/24176_2.png) [@jhogberg](https://forum.elixirforum.com/u/jhogberg)\
**Post date:** [November 21, 2023, 8:28am UTC](https://forum.elixirforum.com/t/erlang-term-to-binary-and-postgresql-invalid-byte-sequence-for-encoding-utf8/59862/2 "2023-11-21T08:28:49Z")

</div>

`term_to_binary/1,2` produces a binary in the external term format, not a UTF-8-encoded binary, so this seems like a problem with the schema (by the looks of it on the database server side). Try looking into why `field :state, :binary` implies UTF-8 encoding.

---

_[View the full topic](https://forum.elixirforum.com/t/erlang-term-to-binary-and-postgresql-invalid-byte-sequence-for-encoding-utf8/59862)._
