Can someone please shed some light on this error?

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 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:
          (api) lib/api/domain/accounts/accounts.ex:337: API.Domain.Accounts.get_user_by_phone_number/2

Can you provide a sample query similar to the one executed in API.Domain.Accounts.get_user_by_phone_number/2 ?

Nothing fancy, just the usual Repo.get_by(User, phone_number: phone_number).

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.

Mentioned issue says that it was fixed in v0.15.5 of postgrex library. Please check if you’re using that or a higher version.

1 Like

I’m using Postgres 12. I suspect the error might be coming from Sage . The above query is wrapped inside a Sage transaction.

Yeap, checked. It’s already using 0.15.5.

Are you by any chance using something like PGBouncer? 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.

Yes, I’m using PGBouncer.

I tried appending binary_parameters=yes as suggested in the article but it still throws error randomly.

Only other thing I could recommend trying is: Can you start Postgrex to specify unnamed queries from Ecto?

1 Like

Wow! This is it! Thank you so much!

Great! Glad to be of help :slightly_smiling_face:

1 Like