ViperCoderJay
Pull out bulk data from the database using ecto and sending it as json.
Somewhere within the data is an invalid byte 0xFA utf8 code, my code to pull the data
data = Transactions
|> where([a], a.serviceType in [6, 7] and is_nil(a.deleted_at))
|> join(:left, [a], b in User, on: a.transactingUser_id == b.id)
|> select([a], %{
channel: a.channel,
plaza: a.startRoute,
ref: a.transactionRef,
cashier: fragment("concat(?, concat(' ', ?))", b.firstName, b.lastName)
}
|> Repo.all()
json(conn, data)
How can I solve this problem?
If possible, how can I convert it to string within the ecto query itself?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication):
toke...
New
Is there any way to avoid the Hologram compiler running when using iex? It seems like the front-end code could potentially be disregarded...
New
** (ArgumentError) expected :max_attempts to be a positive integer, got: {:@, [line: 10, column: 19], [{:max_attempts, [line: 10, column:...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex











Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kip
Please paste code between triple back-ticks (``` before and after) so people have a chance to understand it.
The code point
0xfais valid unicode:So there is something about the sequence of bytes that is making the string be invalid UTF8. That suggests that the encoding of the data in the database is not UTF8.
You could confirm the encoding of your database with:
It would also be helpful if you can post the complete binary that is invalid so we can investigate further.
NobbZ
The codepoint
U+00fais valid unicode as you have shown, though the problem is the byte.The byte
0xFAalone is not valid UTF-8, as can be seen in this table:0xFAis marked red, which means “is not allowed to appear in a UTF-8 encoded sequence of bytes”.NobbZ
Can you please share the full error? that migh help to understand where it comes from.
Also please share your relevant schema and migrations.
ViperCoderJay
thats the error am giving
ViperCoderJay
NobbZ
There is a byte
250close to the end. That is the0xFAfrom the error.Please check your database directly what byte there is and fix the data in the database.
The following shows what is exactly in fornt of and after that byte:
ViperCoderJay
So how can I detect the error and replace it with a string directly from the database because my app is crashing when it encounters that error, code example please
kip
As @NobbZ says, the primary issue here is that you have invalid UTF8-encoded data in your database. Therefore the correct fix is to correct the data in your database.
If you are unable to correct the data in your database then:
:binary(not:string).String.chunk(binary, :valid)to split the string into valid and invalid parts.Enum.filter(chunks, &String.valid?/1) |> Enum.join()ViperCoderJay
Thanks alot.
Can’t manage correcting my database manual
Thats the count of transactions I have in the DB. Can’t manage going through it one by one.
thanks
NobbZ
No one said it has to be done manually.
Though in my opinion it has to happen!
Make sure that your database is encoding aware and not just assuming binary/opaque blob of data.
Then write a program that fixes all the malformed data you have according to the policy you have decided to go with.
Keeping malformed data in the DB and reinventing fixes for each consumer of the database is what made us see all the questionmarks and backslashes in the early 2000s, as so many PHP folks tried to fix data before pushing to DB and another set of developers tried to fix when pulling out, leading to “double fixed” data which again was often worse, as the roundtrip of fixing started again with each data edit.
On top of that, developers just didn’t understand all the levels of escaping..