TGViewer
There will be no singularity There will be no singularity @nosingularity · 1.96K subscribers
Post #1262 2.92K
SQL-WTF SQL-TIL

It would seem that what can happen with escaping characters in strings?
Everything has been known for a long time and works the same everywhere...

But what happens if you escape characters that don't need to be escaped?








CREATE TABLE vals(s VARCHAR(5));
INSERT INTO vals(s) VALUES('%');
INSERT INTO vals(s) VALUES('\%');
INSERT INTO vals(s) VALUES('\\%');

SELECT
s,
s LIKE '%' as "%",
s LIKE '\%' as "\%",
s LIKE '\\%' as "\\%"
FROM vals
ORDER BY s;


Now let's run in different databases. Note the values of S.

Snowflake:

| S | % | \% | \\% |
|----|------|------|-------|
| % | TRUE | TRUE | FALSE |
| % | TRUE | TRUE | FALSE |
| \% | TRUE | TRUE | TRUE |


Sqlite:

| s | % | \% | \\% |
|-----|---|----|-----|
| % | 1 | 0 | 0 |
| \% | 1 | 1 | 0 |
| \\% | 1 | 1 | 1 |


Mysql/MariaDB/ClickHouse:

| s | % | \% | \% |
|----|---|----|----|
| % | 1 | 1 | 1 |
| \% | 1 | 0 | 0 |
| \% | 1 | 0 | 0 |


PostgreSQL:

| s | % | \% | \\% |
|-----|------|-------|-------|
| % | true | true | false |
| \% | true | false | true |
| \\% | true | false | true |


Oracle, BigQuery, Databricks and SQL Server don't support this syntax.

So, well... Good thing at least '%' works the same everywhere.....
  • 😱 8
  • 👍 2
  • ❤ 1
More from @nosingularity
  1. Sep 19, 2026fixupx.com/KaiLentit/status/2100629518784328013/video/1
  2. Sep 18, 2026fixupx.com/iam_zachi/status/2100679300756435135
  3. Aug 30, 2026photo post
  4. Aug 25, 2026fixupx.com/meganreyno/status/2091918430374957416
  5. Aug 3, 2026Вышла новость, что Andy Pavlo приняли на борт Clickhouse Inc. Энди довольно известная фигу…
  6. Jul 23, 2026fixupx.com/unclebobmartin/status/2080257779395154409
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →