Thread: plpgsql Integer Concat To String

plpgsql Integer Concat To String

From
Puneet Paul
Date:
Hi,

I want to concatenate a it counter to a string in a
loop in plpgsql.
DECLARE
counter integer := 1;
IdSet char : = 'UniqueId'
IdForEachRun varchar;
BEGIN

IdForEachRun := IdSet || counter;(PROBLEM HERE)
--Or IdForEachRun := IdSet + counter;(PROBLEM HERE)
While condition LOOP

Insert into Table values(IdForEachRun, ......)



counter := counter + 1;
IdForEachRun := IdSet || counter;(PROBLEM HERE)
--Or IdForEachRun := IdSet + counter;(PROBLEM HERE)
END LOOP

END
Language 'plpgsql'

Thanks in advance.

Paul


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

Re: plpgsql Integer Concat To String

From
Rich Hall
Date:
Convert  "counter" into a VARCHAR and coincatinate that to IdSet using
th || operator.
You cannot concatinate data of differing TYPEs.

Rick

Puneet Paul wrote:

>Hi,
>
>I want to concatenate a it counter to a string in a
>loop in plpgsql.
>DECLARE
>counter integer := 1;
>IdSet char : = 'UniqueId'
>IdForEachRun varchar;
>BEGIN
>
>IdForEachRun := IdSet || counter;(PROBLEM HERE)
>--Or IdForEachRun := IdSet + counter;(PROBLEM HERE)
>While condition LOOP
>
>Insert into Table values(IdForEachRun, ......)
>
>
>
>counter := counter + 1;
>IdForEachRun := IdSet || counter;(PROBLEM HERE)
>--Or IdForEachRun := IdSet + counter;(PROBLEM HERE)
>END LOOP
>
>END
>Language 'plpgsql'
>
>Thanks in advance.
>
>Paul
>
>
>__________________________________
>Do you Yahoo!?
>Protect your identity with Yahoo! Mail AddressGuard
>http://antispam.yahoo.com/whatsnewfree
>
>---------------------------(end of broadcast)---------------------------
>TIP 5: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faqs/FAQ.html
>
>
>

--
------------------------------------------------------------------------
A Message from MicroPatent® LLC

MicroPatent now offers searchable .PDF patents!  Save time and improve your workflow efficiencies with these
convenient,easy-to-review documents.  For more information, go to
http://www.micropat.com/0/searchable_pdf/searchable_pdf.html.

Richard Hall
Database Programmer
MicroPatent LLC
250 Dodge Avenue
East Haven, CT  06512
T:  <Phone Number>, x 3321
F:  <Fax Number>
S:  <Toll Free Number>
rhall@micropat.com
www.micropat.com

MicroPatent is an Information Holdings Inc. company (NYSE: IHI).