As far as I’ve observed, I don’t notice any consistent pattern when this gets thrown. Seems the error gets thrown randomly. I tried searching on Google and found this https://github.com/elixir-ecto/ecto_sql/issues/160. But the Github issue doesn’t seem related though. Can someone please show some guidance?
** (exit) an exception was raised:
** (Postgrex.Error) ERROR 26000 (invalid_sql_statement_name) prepared statement "ecto_419" does not exist
(ecto_sql) lib/ecto/adapters/sql.ex:593: Ecto.Adapters.SQL.raise_sql_call_error/1
(ecto_sql) lib/ecto/adapters/sql.ex:526: Ecto.Adapters.SQL.execute/5
(ecto) lib/ecto/repo/queryable.ex:192: Ecto.Repo.Queryable.execute/4
(ecto) lib/ecto/repo/queryable.ex:17: Ecto.Repo.Queryable.all/3
(ecto) lib/ecto/repo/queryable.ex:112: Ecto.Repo.Queryable.one/3
(api) lib/api/domain/accounts/accounts.ex:337: API.Domain.Accounts.get_user_by_phone_number/2
This might be tricky to diagnose. Can you provide more detail like Postgres version? If this happened in other projects before? If you tried to change the Postgres version and check?
I’m not super familiar with Ecto and Postgres, but looks like Ecto created a prepared statement, and when it was trying to execute that with the parameters provided that didn’t exist. For some reason, Ecto of Postgres might be clearing prepared statements.
I’m using Postgres 12. I suspect the error might be coming from Sage https://hex.pm/packages/sage . The above query is wrapped inside a Sage transaction.
Are you by any chance using something like PGBouncer?
https://blog.bullgare.com/2019/06/pgbouncer-and-prepared-statements/ see “prepared statements issue”. If you’re having issues and not using PGBouncer you can maybe still try the binary parameters fix the blog post recommends and at least then you’ve narrowed down your issue if it works.