-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Concat function
PostPosted: Wed Mar 10, 2004 5:29 am 
Hi,

I need to concat two or more strings, but found no help in the Dialect classes of Hibernate. I expected to find either a hibernate function concat() or perhaps a method on Dialect to which I could give a list of strings.
My problem is that the app is expected to run on both PostgresQL and MySQL which uses || and CONCAT respectively.

Could this be a new feature for hibernate, cross-db string concatenation?


Top
  
 
 Post subject: Re: Concat function
PostPosted: Wed Mar 10, 2004 5:43 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
lborupj wrote:
Hi,

I need to concat two or more strings, but found no help in the Dialect classes of Hibernate. I expected to find either a hibernate function concat() or perhaps a method on Dialect to which I could give a list of strings.
My problem is that the app is expected to run on both PostgresQL and MySQL which uses || and CONCAT respectively.

Could this be a new feature for hibernate, cross-db string concatenation?


Create function on PGSQL:

create function CONCAT(TEXT,TEXT) RETURNS TEXT AS'
BEGIN
RETURN $1 || $2;
END;
' language 'plpgsql';

Or concatinate strings in java code.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 2:08 pm 
Hi baliukas,

Thnx for the answer - Im just wondering of the following would
fit your suggestion:

"from package.Object as o where o.uri = ? || name || '/' "

This works on PostgresQL and name is the name of a column.

"from package.Object as o where o.uri = CONCAT(?, name, '/')

..is the MySQL version.

Do you think this would on your pgsql function (aside it should take three parameters as to two)? Im mosly concerned about the name column.


Top
  
 
 Post subject:
PostPosted: Wed Mar 10, 2004 2:46 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It must work without problems, I am not sure, but it must be possible to make postgresql use index for this query with function help too. Just try it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 2:59 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
lborupj wrote:
Hi baliukas,

"from package.Object as o where o.uri = ? || name || '/' "



BTW The right way for this use case is to use query like this:

"from package.Object as o where o.domain = ? "


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.