valderman / selda

A type-safe, high-level SQL library for Haskell
https://selda.link
MIT License
478 stars 58 forks source link

Question on prepared statements #177

Closed collinpeters closed 2 years ago

collinpeters commented 2 years ago

Sorry if this is not the right avenue. I am a non-Haskell engineer working on some systems where Haskell is deployed and Selda is used for connecting to a Postgresql database. We are enabling a DataDog/Postgres integration of which one of the features is query tracking and performance. Behind the scenes it uses explain plans to help diagnose queries.

We are getting an error in the postgres logs complaining that queries that are coming from Selda cannot be processed by Datadog. The Datadog support team sent a link noting that the integration does not work with prepared statements nor the extended query protocol.

I'm trying to find out if Selda is using either of these two things. From the GitHub readme I see the feature "Seamless prepared statements" but in grepping our source I can't see that this is used.

So my questions are simply

  1. Are prepared statements used by default?
  2. Is the Postgres extended query protocol used at all?
  3. Are there any configuration options to control any of this on the Selda side?
valderman commented 2 years ago
  1. Named prepared statements are only used when using prepared. However...
  2. Selda uses the libpq Haskell bindings. More specifically, non-prepared statements use the execParams function, which does indeed look like it uses the extended protocol.
  3. No. If "supplying data values as separate parameters instead of having to insert them directly into a query string" requires use of the extended protocol, any setting to force the simple protocol would not work with Selda. I would also advise against any solution that requires the simple protocol, considering the elevated risk of SQL injections you expose yourself to when interpolating values directly into query strings.
collinpeters commented 2 years ago

Thanks for the info!