473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

CONCAT function

Hello,
As I'm in the middle of the migration process form mysql to pg I found
that there is no CONCAT function which is available in mysql. Can
anybody tell me how to implement this function using plPERL or plPGSQL
language ?
Best wishes,
ML


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #1
12 57407
On Tuesday 16 September 2003 13:45, Marek Lewczuk wrote:
Hello,
As I'm in the middle of the migration process form mysql to pg I found
that there is no CONCAT function which is available in mysql. Can
anybody tell me how to implement this function using plPERL or plPGSQL
language ?


You want to use the || operator, e.g. 'hello' || ' ' || 'world'

Full details of operators and functions can be found in the "data types"
section of the documentation.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #2
>
You want to use the || operator, e.g. 'hello' || ' ' || 'world'


I know that, but in my application (which is working on MySQL now) I
have many querys which use CONCAT function, so I need to implement this
function is PG - there is no possibility to replace (in short time) all
of my querys.


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #3
On 16 Sep 2003 at 14:36, Marek Lewczuk wrote:

You want to use the || operator, e.g. 'hello' || ' ' || 'world'


I know that, but in my application (which is working on MySQL now) I
have many querys which use CONCAT function, so I need to implement this
function is PG - there is no possibility to replace (in short time) all
of my querys.


Write your own function..

something like

text concat(text,text)

return text1 || text2

Check up the syntax but you got the idea..

Bye
Shridhar

--
Friends, n.: People who borrow your books and set wet glasses on them. People
who know you well, but like you anyway.
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #4
>
text concat(text,text)

return text1 || text2


If it would be so simple I would not write to this group. You see,
CONCAT function doesn't have any arguments limitations, so there could
be one, two or more arguments. And this is my problem, how to write
function without given arguments number.


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #5
In the last exciting episode, ne***@lewczuk.com ("Marek Lewczuk") wrote:
You want to use the || operator, e.g. 'hello' || ' ' || 'world'


I know that, but in my application (which is working on MySQL now) I
have many querys which use CONCAT function, so I need to implement this
function is PG - there is no possibility to replace (in short time) all
of my querys.


Well, then you might implement "CONCAT" in plpgsql.

It will presumably take two values (possibly text, possibly generic),
use ||, inside the function, to catenate them, and then return a text
value.

That should be quite straightforward.
--
wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','ntlug.org').
http://cbbrowne.com/info/lisp.html
Rules of the Evil Overlord #220. "Whatever my one vulnerability is, I
will fake a different one. For example, ordering all mirrors removed
from the palace, screaming and flinching whenever someone accidentally
holds up a mirror, etc. In the climax when the hero whips out a mirror
and thrusts it at my face, my reaction will be ``Hmm...I think I need
a shave.''" <http://www.eviloverlord.com/>
Nov 11 '05 #6
Search the recent archives for "DECODE" and "NVL" (those are Oracle
functions, but people had he same problems with them as you with
CONCAT).
The basic idea is that in postgres you can overload functions, so you
can create more versions of the function with different parameter
counts/types. Just make sure you implement all the variations you use in
your code.

Cheers,
Csaba.
On Tue, 2003-09-16 at 15:50, Marek Lewczuk wrote:

text concat(text,text)

return text1 || text2


If it would be so simple I would not write to this group. You see,
CONCAT function doesn't have any arguments limitations, so there could
be one, two or more arguments. And this is my problem, how to write
function without given arguments number.


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #7
On Tue, 16 Sep 2003, Marek Lewczuk wrote:
Hello,
As I'm in the middle of the migration process form mysql to pg I found
that there is no CONCAT function which is available in mysql. Can
anybody tell me how to implement this function using plPERL or plPGSQL
language ?


What's wrong with using the SQL spec || operator?
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #8
On Tuesday 16 September 2003 14:35, scott.marlowe wrote:
On Tue, 16 Sep 2003, Marek Lewczuk wrote:
Hello,
As I'm in the middle of the migration process form mysql to pg I found
that there is no CONCAT function which is available in mysql. Can
anybody tell me how to implement this function using plPERL or plPGSQL
language ?


What's wrong with using the SQL spec || operator?


Because in mysql, SELECT 'a' || 'b' is treated as 'a' OR 'b' and you end up
with a return value of 0. Ho hum.

If I had to choose between coding concat() for PG or the standard operator for
mysql, I think I'd do the same.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 11 '05 #9
On Tue, 16 Sep 2003, Richard Huxton wrote:
On Tuesday 16 September 2003 14:35, scott.marlowe wrote:
On Tue, 16 Sep 2003, Marek Lewczuk wrote:
Hello,
As I'm in the middle of the migration process form mysql to pg I found
that there is no CONCAT function which is available in mysql. Can
anybody tell me how to implement this function using plPERL or plPGSQL
language ?


What's wrong with using the SQL spec || operator?


Because in mysql, SELECT 'a' || 'b' is treated as 'a' OR 'b' and you end up
with a return value of 0. Ho hum.

If I had to choose between coding concat() for PG or the standard operator for
mysql, I think I'd do the same.


there's a switch in MySQL that makes it behave properly.

Given the third choice, I'd throw the switch.
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 11 '05 #10
On Tue, 16 Sep 2003, scott.marlowe wrote:
On Tue, 16 Sep 2003, Marek Lewczuk wrote:
Hello,
As I'm in the middle of the migration process form mysql to pg I found
that there is no CONCAT function which is available in mysql. Can
anybody tell me how to implement this function using plPERL or plPGSQL
language ?


What's wrong with using the SQL spec || operator?


Having read the other bits of this thread now, it seems you'd like to
create a simple function (pl/sql is good enough to so it, no need for
pl/pgsql or what) to do this, but it needs to handle a variable number of
args.

While pgsql doesn't, to the best of my knowledge, support variable number
of arguments, it DOES support overloading. So, you can always create a
series of functions that hand 2, 3, 4, 5, 6, etc.., arguments until you
get enough to handle all the situations you need.

I still stand by my recommendation to start MySQL with the ansi
compatibility switch and use the SQL standard specified || operator for
portability, as the next database you want to port to after Postgresql may
not be flexible enough to do this.

Standards are nice, they improve portability, and while the default
behaviour of MySQL here is not spec, at least they do provide a switch to
make it work the right way.

Of course, if you've got other packaged apps using || as the OR operator,
you might have issues there. But, if the statements of MySQL are to be
taken seriously, i have the feeling that one day || may well be deprecated
as they try to get their database server more and more accepted for the
server room as a replacement for other databases, so you might as well be
ahead of the curve, and not caught by surprise when that happens.
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 11 '05 #11
In an attempt to throw the authorities off his trail, sc***********@ihs.com ("scott.marlowe") transmitted:
Given the third choice, I'd throw the switch.


Why is it that I think of something _completely_ different when you
use the phrase "throw the switch?"

:-)
--
let name="cbbrowne" and tld="acm.org" in name ^ "@" ^ tld;;
http://www3.sympatico.ca/cbbrowne/nonrdbms.html
"The world needs more people like us and fewer like them." -- Unknown
Nov 11 '05 #12
You're not from Texas, are you? :-)

Christopher Browne wrote:
In an attempt to throw the authorities off his trail, sc***********@ihs.com ("scott.marlowe") transmitted:

Given the third choice, I'd throw the switch.


Why is it that I think of something _completely_ different when you
use the phrase "throw the switch?"

:-)

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 11 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Garrett Kajmowicz | last post by:
I'm needed to insert large BLOBs into a database. With the 1MB packet limit, sending larger amounts of data would be difficult, so I had a neat idea. I would do an initial insert of an empty...
4
by: Gerald Aichholzer | last post by:
Hello, I need to specify the following attribute in an xhtml-file containing TAL templates: <div tal:attributes="onMouseOver concat('func(',xyz,')')"> which results in <div...
3
by: lizayica | last post by:
I am using dynamic SQL in my Procedure that has one parameter named Dep_ID varchar(50). Inside procedure, I need one dynamic SQL to fulfill the same function like: select first_name ||...
3
by: Bryan Valencia | last post by:
Ok, I tried to use the concat function. It's in the Help, but it claims it can't find the namespace that contains 'concat'. You'd think there'd be a note in the help system if I have to use some...
8
by: Doug Stiers | last post by:
Is there a downside to using string.concat? Other than a little overhead? str1 = string.concat(str1,str2) vs. str1 &= str2 It seems to me like the string class should be optimized to do this...
4
by: Martin Fletcher | last post by:
I cant get the Concat function to work, please help. Here's some of my code. Module modTCP Public TCP_RECEIVED_DATA As String Private WithEvents TCP_SERVER As New WinSockSVR Private Sub...
1
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
4
by: Martin Evans | last post by:
Hi, I'm getting: DBD::DB2::db do failed: SQL0440N No authorized routine named "CONCAT" of type "FUNCTION" having compatible arguments was found. SQLSTATE=42884 for some SQL like this:
1
by: Sharat Koya | last post by:
I have a the following xml node. <doc tag1="a" tag2="b" tag3="c" docTag1="d" docTag2="e"/> I would like to output "abc" I have the following XPATH2.0 so far //doc/@*] which returns a node...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.