Hi,
My customer has Oracle database and table like as follows.
SQL> DESC test;
Name Null? Type
----------------------------------------- -------- ----------------------------
COL1 VARCHAR2(20)
SQL> select * from test;
COL1
------------------------------------------------------------
1
He has application that run sql like as follows.
SQL> select col1 + 1 from test;
COL1+1
----------
2
He wants to migrate this database to PostgreSQL using orafce, but this sql does not work as follows.
postgres=# \d test
Table "public.test"
Column | Type | Modifiers
--------+--------------+-----------
col1 | varchar2(20) |
postgres=# select * from test;
col1
------
1
(1 row)
postgres=# select col1 + 1 from test;
ERROR: operator is not unique: varchar2 + integer
LINE 1: select col1 + 1 from test;
^
HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
I think the cause of this error is following.
There are following '+' operators that the right argument is integer.
postgres=# \doS+
List of operators
Schema | Name | Left arg type | Right arg type | Result type | Function |
Description
------------+------+-----------------------------+-----------------------------+-----------------------------+--------------------------+------------------------------------------------------------------
...
pg_catalog | + | bigint | integer | bigint | int84pl | add
pg_catalog | + | date | integer | date | date_pli | add
pg_catalog | + | integer | integer | integer | int4pl | add
pg_catalog | + | smallint | integer | integer | int24pl | add
Implicit casts of varchar2 to these four types are defined as follows.
postgres=# \dC
List of casts
Source type | Target type | Function | Implicit?
-----------------------------+-----------------------------+--------------------+---------------
...
varchar2 | bigint | (binary coercible) | yes
varchar2 | date | (binary coercible) | yes
varchar2 | integer | (binary coercible) | yes
varchar2 | smallint | (binary coercible) | yes
Therefore, PostgreSQL cannot choose a '+' oeprator from these four operators.
I have no idea to solve this problem without using explicit cast. He does not want to modify sql.
Do you have any ideas?
Regards,
Ryohei Takahashi