ginkgo36 wrote > But I can not write a function :(. please hepl me. > For example, I have column "data_text" with data like this: > Row 1: AUTO; BODY; PREDILUTED; ECD FORM; RABBIT; FORMAT; CHROMOGENIC > Row 2: ECD FORM; BODY; PREDILUTED; CHROMO-GENIC; AUTO; RABBIT; FORMAT > Row 3: FORMAT; ECD FORM; AUTO > Row 3: ANHYDROUS; DENATURED; PREDILUTED; CHROMOGENIC > > When I run funtion, the result: > Row 1: AUTO; BODY; CHROMOGENIC; ECD.FORM; FORMAT; PREDILUTED; RABBIT > Row 2: AUTO; BODY; CHROMO-GENIC; ECD FORM; FORMAT; PREDILUTED; RABBIT > Row 3: AUTO; ECD FORM; FORMAT > Row 4: ANHYDROUS; CHROMOGENIC; DENATURED; PREDILUTED Assuming what you show above is your goal writing such a function is straight-forward. Basically you take your existing SQL and wrap it in a CREATE FUNCTION. The input would be of type "text" as would the output. Inside the function you do all the same split/unnest/trim/string_agg actions as you show above. Start you exploration on the syntax and mechanics here: http://www.postgresql.org/docs/9.3/interactive/xfunc.html While you could use pl/pgsql a simple SQL function is sufficient for your needs. Post a specific question with your attempted "CREATE FUNCTION" if you get stuck. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/String-reverse-funtion-tp5773871p5774647.html Sent from the PostgreSQL - general mailing list archive at Nabble.com. -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general