Re: Fwd: String reverse funtion?

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Fwd: String reverse funtion?
Date: 2013-10-15 17:25:22
Message-ID: 1381857922621-5774647.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Quang Thoi 2013-10-15 18:38:35 can you do rollback in a trigger function?
Previous Message ginkgo36 2013-10-15 16:24:38 Re: Fwd: String reverse funtion?