Postgresql 如何删除'\t''\n';还是Postgres中字符串的额外空格?
我在Postgres中有一个表,表中有以下列:Postgresql 如何删除'\t''\n';还是Postgres中字符串的额外空格?,postgresql,trim,regexp-replace,Postgresql,Trim,Regexp Replace,我在Postgres中有一个表,表中有以下列: col1 The study was terminated early by the sponsor on 13 January 2014 due to a decision to modify the drug development plan. Due to positive preliminary results from other palifermin studies. Asset ter
col1
The study was terminated early by the sponsor on 13 January 2014 due to a decision to modify the drug development plan.
Due to positive preliminary results from other palifermin studies.
Asset terminated by PIB
Inconsistent training status of sniffer dogs
This study was terminated early due to poor recruitment
The study was terminated due to lack of recruitment.
The scientific director decided to terminate: low priority study with slow accrual
See Termination Reason in Detailed Description.
Investigator moved to new institution
This study was terminated for administrative reasons
The app was not completed in time to conduct a clinical trial on it within the funding grant's award period
字符串中有前导空格和后导空格,中间有“\n”或“\t”。我尝试了以下问题,但似乎没有任何结果
select btrim(col1, '\s') from table;
update table
SET col1 = upper(substring(REGEXP_REPLACE(col1, '(\s+)', '') from 1 for 1)) || lower(substring(REGEXP_REPLACE(why_stopped, '(\s+)', '') from 2));
update table
set col1= regexp_replace(col1, E'[\\n\\r\\f\\u000B\\u0085\\u2028\\u2029]+', ' ', 'g' );
select distinct replace( replace( replace( col1, E'\n', '\n' ), E'\t', '\t' ), E'\r', '\r' )
from table;
这里的任何建议都非常有用。要在字符串文本中使用反斜杠转义,必须在它们前面加上
E
;看
所以试试看
btrim(col1, E' \t\n')
可以使用trim()函数
您可以在此处找到示例:
我通过以下方式解决了这个问题: regexp_replace(为什么_停止,'\s{2,}',''g')
TRIM([LEADING | TRAILING | BOTH] [characters] FROM string)