Skip to content

escape :: as : in named queries #91

Closed

Description

@jmoiron

Discussed a bit at length in #85, it is currently impossible to write queries that should contain a literal :. The named query parsing should be modified to allow for that by allowing the :: escape to mean a single : in the result query. This follows from the sql standard's '' to escape ' inside string literals.

This will be unlikely to have much impact on current uses of sqlx; there is no valid use of :: currently for named statements.

Activity

  1. oreqizer commented on Jul 22, 2017

    @oreqizer

    can this be documented, please? I've been battling two hours with this issue and haven't found it documented anywhere.
    can create PR if yes

  2. dhduvall commented on Jun 5, 2019

    @dhduvall

    In particular, I needed to use this in order to escape the colons in a named query that included a cast:

    VALUES (:structmember ::::bytea)
    

    I'm not sure if I would have seen the documentation before figuring this out, but I agree that having something in the illustrated guide, at least, would be useful. Of particular note is the space in between; sqlx's parser will complain otherwise, and postgres doesn't care.

    Though

    VALUES (CAST (:structmember AS bytea))
    

    works without the need for any colons (if more verbosely), which I hadn't realized when I first encountered this problem.

  3. added a commit that references this issue on May 8, 2024
    aa6f196
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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