Skip to content

ensure concat ops are used for contains / startswith / endswith independently of datatype #8253

Closed

Description

@palisadoes

Describe the use case

The existing documentation for these methods only has examples using strings. The examples are not applicable to VARBINARY columns where the queries fail.

  1. ColumnOperators.contains()
  2. ColumnOperators.endswith()
  3. ColumnOperators.like()
  4. ColumnOperators.startswith()

Databases / Backends / Drivers targeted

N/A

Example Use

The respective sections of documentation should be updated with edited text equivalent to the suggestions below:

ColumnOperators.contains()

  • When byte strings are stored in the database columns (eg. VARBINARY), you should use standard SQL wildcards with the like() method to represent .contains():
stmt = select(sometable).where(
    sometable.like(func.concat(func.concat('%', 'foobar'.encode()), '%'))
)    

Using .contains() with the same concatenations will produce an equivalent result.

ColumnOperators.startswith()

  • When byte strings are stored in the database columns (eg. VARBINARY), you should use standard SQL wildcards with the like() method to represent .startswith():
stmt = select(sometable).where(
    sometable.like(func.concat(func.concat('foobar'.encode()), '%'))
)    

Using .startswith() with the same concatenations will produce an equivalent result.

ColumnOperators.endswith()

  • When byte strings are stored in the database columns (eg. VARBINARY), you should use standard SQL wildcards with the like() method to represent .endswith():
stmt = select(sometable).where(
    sometable.like(func.concat(func.concat('%', 'foobar'.encode())))
)    

Using .endswith() with the same concatenations will produce an equivalent result.

Additional context

N/A

Activity

  1. added
    requires triage
    use case
    on Jul 13, 2022
  2. zzzeek commented on Jul 13, 2022

    @zzzeek
    Member

    So I dont think a document here is sufficient, because people tend not to find docs like these.

    What I would prefer is:

    1. we figure out what these operators should do when passed a bytestring and do that
    2. we have it raise an error

    1 is likely preferable

  3. changed the title [-]Docs: VARBINARY column support for `.contains()`, `.like()`, etc. [/-] [+]VARBINARY column support for `.contains()`, `.like()`, etc. [/+] on Jul 13, 2022
  4. changed the title [-]VARBINARY column support for `.contains()`, `.like()`, etc. [/-] [+]_Binary column support for string operations - should implement, or raise[/+] on Jul 13, 2022
  5. added
    datatypes
    and removed
    requires triage
    on Jul 13, 2022
  6. added this to the 2.x.x milestone on Jul 13, 2022
  7. added
    help wanted
    on Jul 13, 2022
  8. sqla-tester commented on Jul 17, 2022

    @sqla-tester
    Collaborator

    Mike Bayer has proposed a fix for this issue in the main branch:

    use concat() directly for contains, startswith, endswith https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3996

  9. sqla-tester commented on Jul 17, 2022

    @sqla-tester
    Collaborator

    Mike Bayer has proposed a fix for this issue in the rel_1_4 branch:

    use concat() directly for contains, startswith, endswith https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3997

  10. modified the milestones: 2.x.x, 1.4.x on Jul 17, 2022
  11. removed
    help wanted
    on Jul 17, 2022
  12. changed the title [-]_Binary column support for string operations - should implement, or raise[/-] [+]ensure concat ops are used for contains / startswith / endswith independently of datatype[/+] on Jul 17, 2022
  13. added a commit that references this issue on Jul 18, 2022
    0052827
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

    datatypesuse case

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions