Thread: Concatenating

Concatenating

From
Juan Francisco Diaz
Date:
Hi, i have this:

cadena := 'select * from orden where idlibro = ';
cadena := cadena || Libro;
cadena := cadena || ' order by idorden limit ';
cadena := cadena || ''numFin'';
cadena := cadena || ';';

And I cant get it to wrok. Libro and numFin are variables that are received
in a pgsql function. Libro is char(6) and numFin is numeric.
I tried this and also doing everything in the same line... With no good
results... Iam now very confused with this!!!! AHAHHAHAh
Any helpgratly appreciated.

JuanF
"a newbie with quotes in his head"


Re: Concatenating

From
Heath Tanner
Date:
On Tuesday, September 23, 2003, at 06:08  PM, Juan Francisco Diaz wrote:

> cadena := 'select * from orden where idlibro = ';
> cadena := cadena || Libro;
> cadena := cadena || ' order by idorden limit ';
> cadena := cadena || ''numFin'';
> cadena := cadena || ';';
>
> And I cant get it to wrok. Libro and numFin are variables that are
> received
> in a pgsql function. Libro is char(6) and numFin is numeric.
> I tried this and also doing everything in the same line... With no good
> results... Iam now very confused with this!!!! AHAHHAHAh

Looks like you need to double your quotes, e.g. ''select * from orden
where idlibro = ''.

See "19.11.1.1. Quote Me on That: Escaping Single Quotes":
http://www.postgresql.org/docs/7.3/interactive/plpgsql-porting.html.

-heath