Skip to content

Text protocol support ? What are the downsides?Β #882

Open
@Weakky

Description

@Weakky

Context

(If you wanna get straight to the point, you can skip this context and read the second part)

Hey, so we've been using tokio-postgres at Prisma for quite a while now. Very briefly, Prisma is a JavaScript ORM-like with a backend in rust. We use rust for various reasons that aren't relevant to my question here.

The ability for our users to send "raw" queries is an essential escape hatch. Unfortunately, we're seeing quite a lot of our users confused as to why they're unable to query a bunch of PG types that Prisma doesn't officially support, even with raw queries. eg: PostGIS types. They're especially confused because 99.9% of JS ORMs are based on the node-postgres driver, which uses the text protocol under the hood and so these queries fetching custom types used to work for them.

The underlying reason, obviously, is that we don't have ToSql/FromSql traits implemented for those types.

This leaves us with two options:

  1. Suggest them to TEXT cast those types if they wish to query them
    • 🟑 That's an ok workaround but that prevents them from SELECT *.
  2. Gradually support more types
    • πŸ”΄ We need those escape hatch to work reliably without us intervening, otherwise we'd just officially support those types.

It might be possible to just forward those bytes to the Javascript side and enable users to parse them themselves, but the binary representation makes it much harder for common users. Worse, it seems like the best existing documentation as to how complex types should be deserialized is by reading the PG codebase, which is not amazing from a DX point of view when you're just willing to execute a query.

What would be much more approachable for our users is to receive a text representation for those unsupported types which they can easily parse if they wish so. In a lot of cases, it is hacky and/or inefficient, but that's how the JS community does it already anyway.

This brings me to my question πŸ‘‡πŸ»

Text protocol, what are the downsides?

We've recently investigated the PG protocol in the hope of finding downsides to the text protocol, but we haven't really. The extended query flow documentation says types can individually be requested either as string or as binary (and this discussion too).

Now, as the title asks, what are the downsides of using the text protocol, and why does rust-postgres prefer using the binary protocol? Are there common PG types that lack a text representation? Does it lead to type ambiguities in some cases? Does it have performance implications?

If there are no clear downsides though, is there any chance you'd be ok having rust-postgres support that protocol?

Thanks for your time, cheers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions