Thread: plpgsql string concatanation
Is it posible to do string concatanation in plpgsql? Somthing like: sec := ''some string here'' . NEW.id; Is there a way to do this? I need te value of that new string for things that come after, and couldn't find much in the PL documentation. -- 09:01:02 up 2 days, 15:25, 1 user, load average: 0.17, 0.20, 0.19 ----------------------------------------------------------------- Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral -----------------------------------------------------------------
Martin Marques <martin@bugs.unl.edu.ar> writes: > Is it posible to do string concatanation in plpgsql? > > Somthing like: > > sec := ''some string here'' . NEW.id; > > Is there a way to do this? I need te value of that new string for things that > come after, and couldn't find much in the PL documentation. Oddly enough, your signature holds the key! > -- > 09:01:02 up 2 days, 15:25, 1 user, load average: 0.17, 0.20, 0.19 > ----------------------------------------------------------------- > Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar' -Doug
El Vie 28 Nov 2003 09:04, escribió: > Is it posible to do string concatanation in plpgsql? > > Somthing like: > > sec := ''some string here'' . NEW.id; > > Is there a way to do this? I need te value of that new string for things > that come after, and couldn't find much in the PL documentation. Sorry for the stupid question. I got it, and it was always on MY FACE. :-( CONCATENATION, why can't I think simple. ;-) -- 09:41:02 up 2 days, 16:05, 1 user, load average: 0.87, 1.19, 0.98 ----------------------------------------------------------------- Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral -----------------------------------------------------------------
El Vie 28 Nov 2003 09:44, Doug McNaught escribió: > Martin Marques <martin@bugs.unl.edu.ar> writes: > > Is it posible to do string concatanation in plpgsql? > > > > Somthing like: > > > > sec := ''some string here'' . NEW.id; > > > > Is there a way to do this? I need te value of that new string for things > > that come after, and couldn't find much in the PL documentation. > > Oddly enough, your signature holds the key! Exactly!!!! That makes me fill even worst! :-( As I said, it was in front of me, and the tree didn't let me see the forest. :-) -- 09:43:01 up 2 days, 16:07, 1 user, load average: 1.14, 1.34, 1.07 ----------------------------------------------------------------- Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral -----------------------------------------------------------------
> Is it posible to do string concatanation in plpgsql? > > Somthing like: > > sec := ''some string here'' . NEW.id; > > Is there a way to do this? I need te value of that new string for things > that come after, and couldn't find much in the PL documentation. String concatenation is done via the '||' operator see http://www.postgresql.org/docs/current/static/functions-string.html Joerg
One thing that I always have to remind myself of is this: string || NULL is NULL. It is usually a good idea to use coalesce() unless you want this to happen. Best wishes, CHris Travers ----- Original Message ----- From: "Martin Marques" <martin@bugs.unl.edu.ar> As I said, it was in front of me, and the tree didn't let me see the forest. :-) -- 09:43:01 up 2 days, 16:07, 1 user, load average: 1.14, 1.34, 1.07 ----------------------------------------------------------------- Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral ----------------------------------------------------------------- ---------------------------(end of broadcast)--------------------------- TIP 7: don't forget to increase your free space map settings
> One thing that I always have to remind myself of is this: > > string || NULL is NULL. > It is usually a good idea to use coalesce() unless you want this to > happen. > See my recent post at http://www.brasileiro.net/postgres/cookbook/view-one-recipe.adp?recipe_id=24725 (and in general, everyone here who hasn't looked at http://www.brasileiro.net/postgres/cookbook/ should review all the great goodies posted there). ~Berend Tober
El Vie 28 Nov 2003 10:38, Chris Travers escribió: > One thing that I always have to remind myself of is this: > > string || NULL is NULL. > It is usually a good idea to use coalesce() unless you want this to happen. Pretty nice. :-) Even though I don't have that problem, becuase the value comes from a PK field. -- 11:24:01 up 2 days, 17:48, 1 user, load average: 0.56, 0.62, 0.63 ----------------------------------------------------------------- Martín Marqués | select 'mmarques' || '@' || 'unl.edu.ar' Centro de Telematica | DBA, Programador, Administrador Universidad Nacional del Litoral -----------------------------------------------------------------