# Best Postgresql binding?

**URL:** <https://discuss.ocaml.org/t/best-postgresql-binding/11169>\
**Category:** Ecosystem\
**Tags:** postgresql\
**Created:** [January 12, 2023, 8:20pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169 "2023-01-12T20:20:39Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [January 12, 2023, 8:20pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/1 "2023-01-12T20:20:39Z")

</div>

I see that there are a bunch of different Postgresql interfaces for OCaml. Caqti, PGO’Caml, PostgreSQL-OCaml, PGX. Does anybody know of a comparison of all these, maybe to help guide somebody making a choice of which to use ?

---

<div class="post-metadata">

**Author:** ![jfeser](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jfeser/32/2093_2.png) [@jfeser](https://discuss.ocaml.org/u/jfeser)\
**Post date:** [January 12, 2023, 8:32pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/2 "2023-01-12T20:32:59Z")

</div>

If you want PostgreSQL specifically, I’ve had good luck with postgresql-ocaml. It’s a thin wrapper around libpq. It doesn’t have type safe query builders or value (de)serialization.

I think pgx has a pure ocaml implementation of the libpq wire protocol. I’d be interested to hear from anyone who has experience with it.

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [January 12, 2023, 8:40pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/3 "2023-01-12T20:40:27Z")

</div>

My friends “in the biz” tell me that postgresql is the database to go with these days. My response for the last 15yr has always been to go with Mysql, but … clearly, given the pretty much _unanimous_ view of the folks I queried that Postgresql is the way to go, I’ve decided to take the plunge.

---

<div class="post-metadata">

**Author:** ![jfeser](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jfeser/32/2093_2.png) [@jfeser](https://discuss.ocaml.org/u/jfeser)\
**Post date:** [January 12, 2023, 8:45pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/4 "2023-01-12T20:45:09Z")

</div>

I like Postgres personally, but using DB specific bindings locks you in a bit. There are other Postgres-compatible DBs though (Redshift, etc.), and you can mostly just swap them in (modulo all their interesting incompatibilities).

The alternative is libs like Caqti that abstract over the DB backend or I guess ODBC.

---

<div class="post-metadata">

**Author:** ![cemerick](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/cemerick/32/1383_2.png) [@cemerick](https://discuss.ocaml.org/u/cemerick)\
**Post date:** [January 12, 2023, 9:06pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/5 "2023-01-12T21:06:59Z")

</div>

Caqti + ppx\_rapper has been my go-to.

---

<div class="post-metadata">

**Author:** ![dangdennis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dangdennis/32/2594_2.png) [@dangdennis](https://discuss.ocaml.org/u/dangdennis)\
**Post date:** [January 12, 2023, 9:10pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/6 "2023-01-12T21:10:26Z")

</div>

While postgresql is the hottest thing to use in startup land, and I enjoy it, the planetscale service makes working with mysql so easy that I sometimes want to start a service with mysql just for their migration and branching ux.

What about mysql bindings? According to ocamlverse, there are way fewer choices for mysql. Which ones are still okay to use if I don’t care about type-safety across the db network layer?

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [January 12, 2023, 9:23pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/7 "2023-01-12T21:23:34Z")

</div>

nevermind, found planetscale.

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [January 12, 2023, 9:37pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/8 "2023-01-12T21:37:32Z")

</div>

> [@dangdennis](#):
>
> What about mysql bindings?

One of the reasons I thought about Mysql (other than “I’ve always used it when I didn’t have to use DB2”) was `myrocks`: Mysql with RocksDB replacing the InnoDB storage engine. B/c boy howdy, SSD-friendliness is a good thing. And apparently really improves performance.

My friends’ urging of Postgresql was dispositive, though: they’re all in positions where these things matter, and not only in startups.

---

<div class="post-metadata">

**Author:** ![benjamin-thomas](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/benjamin-thomas/32/3966_2.png) [@benjamin-thomas](https://discuss.ocaml.org/u/benjamin-thomas)\
**Post date:** [January 12, 2023, 11:26pm UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/9 "2023-01-12T23:26:46Z")

</div>

pgocaml looks very appealing to me, for the “magical” type safety you get out of the box, with very minimal friction.

The database’s default authentication method is incompatible with the library since v14 FYI.

So you may find this Dockerfile helpful to set things up.

> <https://github.com/benjamin-thomas/multi-playground/blob/289f315eedfe7a4a282944ca8f71319dd167b7ec/db/docker-compose.yml>

---

<div class="post-metadata">

**Author:** ![jaycle](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jaycle/32/4161_2.png) [@jaycle](https://discuss.ocaml.org/u/jaycle)\
**Post date:** [January 13, 2023, 1:26am UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/10 "2023-01-13T01:26:21Z")

</div>

Planetscale does look cool. There’s also [https://neon.tech/](https://neon.tech/), which I’ve been hoping to use one day. RDBMS is anything but boring tech these days.

This was a good episode where some tech was covered: [Taking Postgres serverless with Nikita Shamgunov from Neon (The Changelog #510) |\> Changelog](https://changelog.com/podcast/510)

---

<div class="post-metadata">

**Author:** ![dangdennis](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dangdennis/32/2594_2.png) [@dangdennis](https://discuss.ocaml.org/u/dangdennis)\
**Post date:** [January 13, 2023, 2:02am UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/11 "2023-01-13T02:02:03Z")

</div>

I enjoyed that episode too. RDBMS has a made comeback 😆. I look forward to seeing neon being really put through the ringer. Cockroachdb’s serverless offering too is something we’re using. Not in production yet but think it’ll do fine for such an early product. Overall, great options out there now.

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [January 13, 2023, 3:25am UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/12 "2023-01-13T03:25:11Z")

</div>

I could swear that I remember Amazon offering Postgresql as part of their RDB offering in the cloud? Isn’t that already close enough to serverless that the difference doesn’t matter? Just curious – for my project, I most definitely don’t want a serverless deployment.

---

<div class="post-metadata">

**Author:** ![jaycle](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/jaycle/32/4161_2.png) [@jaycle](https://discuss.ocaml.org/u/jaycle)\
**Post date:** [January 13, 2023, 3:35am UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/13 "2023-01-13T03:35:11Z")

</div>

Yeah, sorry to take it off-topic with my post. I didn’t want my friend, postgres, to be left out when discussing large scale distributed relation databases.

AWS does have an offering, but it doesn’t scale to zero, which I find compelling for side projects. If you want pay-per-use, you’re stuck with DynamoDB (document) last I checked. I’m definitely not an expert on this though. Professionally, we keep it pretty old-school.

---

<div class="post-metadata">

**Author:** ![Chet\_Murthy](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/chet_murthy/32/1501_2.png) [@Chet\_Murthy](https://discuss.ocaml.org/u/Chet_Murthy)\
**Post date:** [January 13, 2023, 3:47am UTC](https://discuss.ocaml.org/t/best-postgresql-binding/11169/14 "2023-01-13T03:47:28Z")

</div>

Aha, ok, now tracking. The definition of “serverless” includes “no cost when not used”. Thank you for the clarification.
