laurenz / oracle_fdw

PostgreSQL Foreign Data Wrapper for Oracle
http://laurenz.github.io/oracle_fdw/
Other
496 stars 156 forks source link

I think there should be some documentation on manual handling of unsupported types #579

Closed dr-kd closed 1 year ago

dr-kd commented 1 year ago

After much wailing and gnashing of teeth I worked this up. There may be more efficient ways, but this shows a working process:

diff --git a/README.oracle_fdw b/README.oracle_fdw
index 2c4c5b8..1a7cbf9 100644
--- a/README.oracle_fdw
+++ b/README.oracle_fdw
@@ -394,11 +394,21 @@ Inserting or updating XMLTYPE only works with values that do not exceed the
 maximum length of the VARCHAR2 data type (4000 or 32767, depending on the
 `MAX_STRING_SIZE` parameter).

-NCLOB is currently not supported because Oracle cannot automatically convert
+NCLOB is currently not supported because Oracle cannot _automatically_ convert
 it to the client encoding.

 If you need conversions exceeding the above, define an appropriate view in
-Oracle or PostgreSQL.
+Oracle and/or PostgreSQL. For example to handle NCLOB from utf8 to utf8,
+this scheme works:
+
+    -- First create a view in oracle to convert the nclob to blob
+    CREATE VIEW myview AS SELECT to_blob(utl_raw.cast_to_raw(mycol) FROM mytable;
+
+    -- Then create a foreign table on the view
+    CREATE FOREIGN TABLE foreign_schema.mytable_bytes ( mycol bytea ) SERVER ...
+
+    -- And finally a view in the foreign schema to represent the data to postgres correctly:
+    CREATE VIEW foreign_schema.mytable as ( covert_from(mycol, 'UTF8') from foreign_schema.mytable_bytes;
laurenz commented 1 year ago

Thanks for the initiative, but I think that this is too specific to add to the general documentation. It is for one specific data type, and it will only work when you have small NCLOBs that can be converted to RAW.

It is still good that you created an issue for that, because now others can find your workaround. I also want to encourage you to add something to the Wiki: https://github.com/laurenz/oracle_fdw/wiki