PostgreSql +属性之间有 \r 的查询语句!
假设我们有一个文本区域,在其中放置示例字符串。文本框包含:
Earth is revolving around the Sun.
但在保存时,我只是在“太阳”之后按了回车键。现在 texbox :: Now 中的语句
Earth is revolving around
the Sun
,在按下 Enter 的数据库中,\r 被存储。现在我正在尝试获取数据但无法,因为我的查询是这样的类型 ::
SELECT * FROM "volume_factors" WHERE lower(volume_notes) like E'atest\\r\\n 100'
实际数据存储在数据库字段中
atest\r
100
请建议我解决问题。我已尝试使用 gsub 替换但没有更改。
search_text_array[1] = search_text_array[1].gsub('\\r\\n','\r\n')
提前致谢 !!!
Suppose we have a textarea in which we put example string. Textbox contain :
Earth is revolving around the Sun.
But at the time of saving, I just pressed a enter key after "the sun". Now the statements in texbox ::
Earth is revolving around
the Sun
Now, in database where enter was pressed the \r is stored. Now i am trying to fetch the data but unable, because my query is of such type ::
SELECT * FROM "volume_factors" WHERE lower(volume_notes) like E'atest\\r\\n 100'
Actual data stored in database field
atest\r
100
Please suggest me to solve the issue.I have tried gsub to replace but no change.
search_text_array[1] = search_text_array[1].gsub('\\r\\n','\r\n')
Thanks in Advance !!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
即将数据库中已有的数据用一个空格替换 crlf。您可以使用 postgresql 的 psql 来执行此操作。
为了防止包含 crlf 的新数据进入数据库,您应该在应用程序中执行此操作。如果你使用ruby的gsub,不要使用单引号,使用双引号来识别\n,如下所示:
Try this:
That's to replace crlf with one space for data that is already in the database. You use postgresql's psql to do this.
To prevent new data containing crlf entering database, you should do it in the application. If you use ruby's gsub, do not use single quote, use double quote to recognize \n like this:
这里我们可以将
\r\n
替换为%
来获取数据。搜索查询将是这样的 ::
gsub function ::
Here we can replace
\r\n
by%
to fetch the data.Seaching Query will be like this ::
gsub function ::