PostgreSQL 9.3:STUFF 和 CHARINDEX 函数

MAK*_*MAK 7 postgresql postgresql-9.3

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

以下是该字符串的示例:

示例:在 SQL Server 中

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

SELECT STUFF(@Names,1,CHARINDEX(',',@Names,0),'');
Run Code Online (Sandbox Code Playgroud)

在引用此后:Postgresql 中 SQL Server 的 'stuff' 和 'for xml path('')'

String_agg在这种情况下无法帮助我。

Hou*_*ari 9

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

例如:

SELECT STUFF('abcdef', 2, 3, 'ijklmn');
Run Code Online (Sandbox Code Playgroud)

select overlay('abcdef' placing 'ijklmn' from 2 for 3)
Run Code Online (Sandbox Code Playgroud)

给出相同的结果:

'aijklmnef'
Run Code Online (Sandbox Code Playgroud)

换句话说:

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.
Run Code Online (Sandbox Code Playgroud)