Mapping Oracle types to PostgreSQL types

From: Jean-Michel POURE <jm(at)poure(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Mapping Oracle types to PostgreSQL types
Date: 2003-10-17 08:10:26
Message-ID: 200310171010.26003.jm@poure.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-advocacy pgsql-hackers

Dear friends,

I would like to port Compiere CRM from Oracle to PostgreSQL (and release it
for free).

At first I would like to convert the data schema. This is not difficult as
Compiere is written using portable types like NUMBER (i,d) which can be
replaced by NUMERIC (i,d), etc... A series of Search/Replace is sufficiant.
There are other solutions in Contrib to connect to Oracle and export the data
(Bruce). Don't blame me to search in another (silly) direction...

The point here is that I would like to use the CREATE TYPE or CREATE DOMAIN
syntax to map Oracle types to PostgreSQL types. Therefore I can say "Guys,
Oracle is now mostly compatible with PostreSQL".

In PostgreSQL, I used CREATE TYPE syntax to map
Oracle nvarchar2 -> PostgreSQL varchar (see code #1).

The code seems to be the equivalent of "CREATE DOMAIN nvarchar2 as varchar;"

Now I can create tables with nvarchar2 but not nvarchar2(lenght).

Is there a way to map Oracle nvarchar2(lenght) to PostgreSQL varchar(lenght)
in PostgreSQL 7.3? Are there plans to allow such mapping in the future using
the CREATE DOMAIN syntax?

Best regards,
Jean-Michel Pouré

**********************************************************************
Code #1
--DROP TYPE nvarchar2 CASCADE;

CREATE OR REPLACE FUNCTION oracle_nvarchar2in(cstring, oid, int4)
RETURNS nvarchar2 AS
'varcharin'
LANGUAGE 'internal' IMMUTABLE STRICT;
COMMENT ON FUNCTION oracle_nvarchar2in(cstring, oid, int4) IS '(internal)';

CREATE OR REPLACE FUNCTION oracle_nvarchar2out(nvarchar2)
RETURNS cstring AS
'varcharout'
LANGUAGE 'internal' IMMUTABLE STRICT;

CREATE TYPE nvarchar2
(INPUT=oracle_nvarchar2in, OUTPUT=oracle_nvarchar2out, DEFAULT='',
INTERNALLENGTH=-1, ALIGNMENT=int4, STORAGE=EXTENDED);
COMMENT ON TYPE nvarchar2 IS 'Oracle type nvarchar2(length) mapped to
PostgreSQL type varchar(lenght)';

Responses

Browse pgsql-advocacy by date

  From Date Subject
Next Message Arcadius A. 2003-10-17 08:46:58 Re: pg_hba
Previous Message Neil Conway 2003-10-17 04:50:35 Re: MySQL interview, no mention of PostgreSQL

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2003-10-17 11:40:09 Re: Mapping Oracle types to PostgreSQL types
Previous Message Topmind 2003-10-17 06:14:09 Re: Dreaming About Redesigning SQL