`text.contains` underspecified: Text or pattern?

オープン
#5,751 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
ドキュメント
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
rust, sql
領域
backend

調査の方向性

Start with the linked standard-library documentation for text functions and the issue's examples of generated SQL. Clarify whether contains, starts_with, and ends_with should accept patterns or literal text, then document the intended behavior; the issue does not name source files or tests. The issue is stale and discusses broader SQL-dialect design choices, so check for a maintainer decision before starting.

索引モデルが issue の本文から書いたものです。

説明

What's up?

The text substring search functions (contains, starts_with, ends_with) take a pattern rather than plain text, which may be surprising.

The documentation doesn't specify if it's a substring or a pattern.

Since it doesn't escape special characters, it is treated like a pattern, so wildcards pass through:

  • Input: filter (text.contains '%ne_dle' haystack)
  • Output: AND haystack LIKE CONCAT('%', '%ne_dle', '%')
  • The current behavior uses CONCAT to surround the input with %, even if you give a literal. (Some SQL flavors don't allow three args to CONCAT, such as Oracle before 23, and Redshift.)

What's the intended behavior? It should be documented.

  • If it's intended to be a pattern:
    • For literals, it SHOULD just do LIKE '%ne_dle%', right? This is a minor optimization.
  • If it's meant to be plain text:
    • Escape: LIKE '%ne\_dle%' ESCAPE '\'
      • Transact-SQL: Special characters are %_[].
      • The escape character can be any symbol character which isn't in the string, or else it would need to double existing escape characters in the string.
    • Use INSTR(haystack, 'ne_dle') > 0.
      • Microsoft's Transact: CHARINDEX instead of INSTR.
      • For starts_with, compare to = 1.
      • For ends_with, this may be complicated.
        • INSTR(haystack, 'ne_dle', -1) will search backwards, but the right value is dependent on the lengths of both strings: = LENGTH(haystack) - LENGTH('ne_dle') + 1
        • MySQL doesn't have three-arg INSTR. Instead, it has LOCATE, which can't search from the end of the string, so it will return the first position.
        • SUBSTR(haystack, LENGTH(haystack) - LENGTH('ne_dle') + 1) = 'ne_dle', but may be inefficient by copying.
        • REVERSE turns ends_with into starts_with, but may be inefficient.

If it's supposed to be plain text, it may also be useful to give LIKE as an alternative, such as a text.like function (#1123). I don't know what the project's principle is for handling differences in LIKE syntax.

主要言語
Rust
スター
10.9k
フォーク
261
平均マージ
3日 21時間
マージ済み PR(30日)
84

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PRQL/prql のほかの issue

PRQL/prql の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。