postgresql - Does a new line character affect Postgres LIKE text search?
问题描述
So I have the following stored in a text column in Postgres...
This is a sentence.\nAnd here we start a new sentence.\nThen finally we have a third sentence.
Will those \n
affect a LIKE
query on that column?
i.e. SELECT "tracks".* FROM "tracks" WHERE (info LIKE '%sentence%')
The reason I ask is I want the line breaks for properly formatting the output of the text, but obviously don't want them screwing up search.
解决方案
只要您将换行符存储为换行符,它就不会弄乱您的查询。
CREATE TABLE example(
id serial PRIMARY KEY,
text TEXT NOT NULL
);
INSERT INTO example (text) VALUES (E'This is a sentence.\nAnd here we start a new sentence.\nThen finally we have a third sentence.')
SELECT * FROM example WHERE text LIKE '%nAnd%'; -- 0 records returned
SELECT * FROM example WHERE text LIKE '%And%'; -- 1 record returned
E
当我将它插入表格时,请注意字符串之前的内容。
推荐阅读
- flutter - 我如何在颤振中创建自定义进度指示器
- c - 给定一个整数矩阵 [n] [m],如何扫描子矩阵 [dim] [dim] 中的最大值?C
- jquery - 计算 div 元素并将类附加到其父容器
- python - 在整个参数空间/二维数组上应用函数,Numpy
- python-3.x - 在pycharm中安装gdal
- javascript - 如果输入字段为空,Javascript 禁用和启用按钮
- java - 如何从 Java 中的 while 循环中返回 count 的值
- logstash - 带有动态主机的 Logstash 输入
- c# - XML 名称不能以“=”字符开头
- snowflake-cloud-data-platform - 从 s3 阶段读取时需要选择存储桶名称