'stuff' and 'for xml path('')' from SQL Server in Postgresql

前端 未结 2 1549
太阳男子
太阳男子 2021-01-18 04:37

I\'m migrating some SQL Server 2008R2 queries to Postgresql 9.0 and I have some trouble with it. Here\'s the SQL Server query:

stuff((select \', \'+p.[NAME]          


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 05:07

    You can use string_agg instead.

    SQL Fiddle

    PostgreSQL 9.1.6 Schema Setup:

    create table T
    (
      Name varchar(10)
    );
    
    insert into T values('Kalle');
    insert into T values('Pelle');
    insert into T values('Urban');
    

    Query 1:

    select string_agg(Name, ',') as Names
    from T
    

    Results:

    |             NAMES |
    ---------------------
    | Kalle,Pelle,Urban |
    

提交回复
热议问题