Обсуждение: String concat operator???

Поиск
Список
Период
Сортировка

String concat operator???

От
webmaster
Дата:
I'm trying to update a character field by foll. query:

update temp_kat set id_look = substr(ident,1,6) || '-' || substr(ident,7,7)
where from_kat='P'; 

Both id_look and ident are varchars.. So what's wrong with || operator? There
is an error parsing the querry near || ...

Who is stupid? Me, or postgresql 6.4.2 :) ? It look like legal expression for
me...
--

Michal Samek, Tony distribuce s.r.o.
webmaster@tony.cz  (++420659/321350)
ICQ: 38607210


Re: [SQL] String concat operator???

От
Herouth Maoz
Дата:
At 16:16 +0300 on 30/06/1999, webmaster wrote:


> Both id_look and ident are varchars.. So what's wrong with || operator? There
> is an error parsing the querry near || ...
>
> Who is stupid? Me, or postgresql 6.4.2 :) ? It look like legal expression for
> me...

Old problem... "||" doesn't have associativity, so when you use a||b||c, it
gets mixed up. Solution - use (a||b) || c. Preferably ((a||b)||c).

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




Re: [SQL] String concat operator???

От
Tom Lane
Дата:
webmaster <webmaster@tony.cz> writes:
> update temp_kat set id_look = substr(ident,1,6) || '-' || substr(ident,7,7)
> where from_kat='P'; 

> Both id_look and ident are varchars.. So what's wrong with || operator? There
> is an error parsing the querry near || ...

In 6.4.* you have to parenthesize the above because Postgres doesn't
assume that the operator || is associative:

update temp_kat set id_look = (substr(ident,1,6) || '-') || substr(ident,7,7)
where from_kat='P'; 

6.5 takes the query without parentheses...
        regards, tom lane


Re: [SQL] String concat operator???

От
Bruce Momjian
Дата:
> At 16:16 +0300 on 30/06/1999, webmaster wrote:
> 
> 
> > Both id_look and ident are varchars.. So what's wrong with || operator? There
> > is an error parsing the querry near || ...
> >
> > Who is stupid? Me, or postgresql 6.4.2 :) ? It look like legal expression for
> > me...
> 
> Old problem... "||" doesn't have associativity, so when you use a||b||c, it
> gets mixed up. Solution - use (a||b) || c. Preferably ((a||b)||c).

And fixed in 6.5.


--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026