|| operator

From: Vinayak <vinpokale(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: || operator
Date: 2014-09-03 13:04:46
Message-ID: 1409749486272-5817541.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

The behavior of || operator is different in Oracle and PostgreSQL when the
arguments are CHAR(n) data type.
Example:
create table hoge1(col1 char(10), col2 char(10));
insert into hoge1 values('abc', 'def');
select col1 || col2 from hoge1;
abcdef (PostgreSQL's result)
abc def (Oracle's result)
I think the behavior of CHAR data type is different in Oracle and
PostgreSQL.
CHAR type of Oracle is in the byte unit whereas the CHAR type of PostgreSQL
is in character unit.
Oracle : CHAR(3) => 3 byte
PostgreSQL : CHAR(3) => 3 characters
When CHAR values are stored in Oracle, they are right-padded with spaces to
the specified length.
If we use concat() then the result is same as Oracle || operator so I think
PostgreSQL also store the CHAR value like Oracle but || operator gives the
different result.
Example:
postgres=# select concat(col1,col2) from hoge1;
concat
----------------------
abc def
(1 rows)

postgres=# select col1 || col2 from hoge1;
?column?
----------
abcdef
(1 rows)

Any idea how to get result same as oracle if CHAR(n) data type is used?

-----
Regards,
Vinayak,

--
View this message in context: http://postgresql.1045698.n5.nabble.com/operator-tp5817541.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2014-09-03 13:20:05 Re: || operator
Previous Message Oleg Bartunov 2014-09-03 08:14:36 Re: jsonb and comparison operators