database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
ㆍPostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
PostgreSQL Q&A 2996 게시물 읽기
No. 2996
Aggregate Function (1) -- comma-ify a list
작성자
정재익
작성일
2001-06-21 23:43
조회수
1,868

원본출처 : http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=139

 

 

Submitted on: 04-12-2001

Description:

I use this to denormalize a list into comma-separated values, rather than having to write a separate query to show related records. (Of course, you could also do this w/semicolons, newlines, '

' tags, etc., given your problem. See a longer explanation of these technique at http://www.zope.org/Members/pupq)

Code:

 

-- creat function to comma-ify a list

 

create function comma_aggregate(text,text) returns text as '

begin

if (length($1) > 0 ) then

return $1 || ', ' || $2;

else

return $2;

end if;

end;

' language 'plpgsql';

 

-- create the aggregate function

 

create aggregate comma (basetype=text, sfunc=comma_aggregate, stype=text, initcond='' );

 

-- test it out

 

select fname, lname, comma(hobbies) from people join hobbies on (personid) group by personid, fname, lname;

[Top]
No.
제목
작성자
작성일
조회
2999Error catching
정재익
2001-06-21
1835
2998Operator --- IMP (>>> operator as logical implication)
정재익
2001-06-21
1804
2997Aggregate Function (2) -- first(), last()
정재익
2001-06-21
1733
2996Aggregate Function (1) -- comma-ify a list
정재익
2001-06-21
1868
2995Last-Change Updater
정재익
2001-06-21
1896
2994이전 시간표와 겹치지 않는지 check 하는 함수
정재익
2001-06-21
1710
2993두 datetime 사이의 overlap interval 구하기
정재익
2001-06-21
2040
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다