Skip to content

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

Closed
@palisadoes

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    datatypesthings to do with database types, like VARCHAR and othersuse casenot really a feature or a bug; can be support for new DB features or user use cases not anticipated

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions