PostgreSQL 9.3:STUFF和CHARINDEX函数

时间:2015-03-10 06:35:43

标签: postgresql postgresql-9.3

我想检索给定字符串的某些部分。

以下是字符串的示例:

示例:在SQL Server中

Declare @Names varchar = 'H1,H2,H3,'

SELECT STUFF(@Names,1,CHARINDEX(',',@Names,0),'');

在提到之后:'stuff' and 'for xml path('')' from SQL Server in Postgresql

String_agg无法帮助我解决这个问题。

1 个答案:

答案 0 :(得分:2)

您正在寻找PostgrSQL中STUFF的等效TSQL函数,我认为:overlay

所以例如:

SELECT STUFF('abcdef', 2, 3, 'ijklmn');

select overlay('abcdef' placing 'ijklmn' from 2 for 3)

给出两个相同的结果;

'aijklmnef'
换句话说,

They inserts a string into another string. It deletes a specified length of characters in the 
first string at the start position and then inserts the second string into the first string at 
the start position.