plpgsql Integer Concat To String

Started by Puneet Paulover 22 years ago2 messagesbugs
Jump to latest
#1Puneet Paul
paulptech@yahoo.com

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

#2Rich Hall
rhall@micropat.com
In reply to: Puneet Paul (#1)
Re: plpgsql Integer Concat To String

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).