Ropardo Sowftware development company

Experience software development with ROPARDO S.R.L.

RSS Feed
RSS Feed
  • Home
  • About ROPARDO S.R.L
  • Our websites

Porting applications from Oracle to PostgreSQL

If you are planning to migrate a database application from Oracle to PostgreSQL, this article can help you to understand and solve some of the issues occurring in such a process. PostgreSQL has recently become feature-complete in many areas and therefore porting projects from Oracle might be a feasible option in much more cases. Oracle and PostgreSQL both conform to standard SQL. However, they contain several extensions and implementation details that differentiate one from the other. Here is table with some of the differences and how to deal with them.

Oracle 10g Postgres 8.4 Observations
char(size) char(size) Oracle treats a character value with a length of zero as null. This “weird and inconsistent” behavior is not true for PostgreSQL. Consequently, the ” string must be replaced with NULL.
number(p,s) NUMERIC(precision, scale) For performance reasons, number (p, s) should be replaced with INTEGER, when scale is zero.
varchar2 varchar or text
date date SYSDATE → current_timestamp or now()
clob text
sysdate current_timestamp
decode (expression,
search, result
[, search, result]…
[, default] )
CASE expression
WHEN value THEN result
[WHEN ...]
[ELSE result]
END
or
CASE WHEN condition
THEN result
[WHEN ...]
[ELSE result]
END
The general rule is that NULL is not equal to NULL. But, as an exception, in a DECODE function Oracle considers two nulls to be equivalent. If expression is null, then Oracle returns the result of the first search that is also null (nulls are considered equal in this comparison). This is not true for the SQL-compliant conditional expressions available in PostgreSQL. Therefore, based on the possible values for ‘expression’ and ‘search’, the decode replacement is one of the following:

- CASE expression WHEN search...
- CASE WHEN expression IS NULL...
- CASE WHEN expression = search OR expression IS NULL and search IS NULL...
Outer JOIN Outer JOIN PostgreSQL only supports the SQL-standard outer join syntax. But it is quite easy to translate from the Oracle-specific syntax.
For example,
SELECT * FROM a, b WHERE a.x = b.y(+)
becomes
SELECT * FROM a LEFT JOIN b ON a.x = b.y
Analytic Functions Window Functions Both the Oracle Analytic functions and Postgres Window functions allow you to rank a data set and work with its top-ranked or bottom-ranked rows. A lot of extra work is required because the implementations are very different. Moreover, in PostgreSQL, unlike Oracle, if there is a need to filter or group rows after the window calculations are performed, you have to use a sub-select like in the following simple example:

SELECT depname, empno, salary, enroll_date FROM(SELECT depname, empno, salary, enroll_date, rank() OVER (PARTITION BY depname ORDER BY salary DESC, empno) AS pos FROM empsalary) AS ss WHERE pos < 3
Functions (Oracle’s PL/SQL language) Functions (PostgreSQL’s PL/pgSQL language) Need to register a new language:
CREATE LANGUAGE plpgsql;
In PostgreSQL, the function body is considered to be a string literal, so you need to use quote marks or dollar quotes around it; RETURN key word in the function prototype (not the function body) becomes RETURNS in PostgreSQL; join and cursors syntax must be adjusted, etc.
Months_Between
(Oracle/PLSQL: Function)
No direct replacement is available; but a similar function can be implemented in PostgreSQL’s PL/pgSQL language. Oracle’s MONTHS_BETWEEN (date1, date2) function returns the number of months between dates date1 and date2. This number is computed using a quite intricate algorithm.
|| Operator || Operator An important aspect here is that in PostgreSQL (unlike Oracle) concatenation with a null column nulls the result. If this is not be the behavior you expect, there are several solutions to handle this situation including the use of the SQL CASE WHEN expression, COALESCE or ARRAY_TO_STRING built-in functions.
You can also make use of the PostgreSQL extensibility and create a custom version of the CONCAT operator.
ALTER SESSION
SET CURRENT_SCHEMA = …
SET search_path TO … To permanently alter the search path set on each connection, use:
ALTER USER user_name SET search_path to ...;
This change will only take effect after reconnecting to the database.
date (data type);

timestamp (data type);

to_char(timestamp, text) function;

sign(number) function;

type casts;

substr(string, from [, count]) function;

‘FROM dual’ syntax;

Porting is straightforward
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
Get Shareaholic
Tags: Oracle PostgreSQL

 Posted in: Oracle, PostgreeSQL
July 30, 2010 | Alexandru Gyulai | 3 Comments

3 Responses

  • Porting applications from Oracle to PostgreSQL « DbRunas – Noticias y Recursos sobre Bases de Datos
    July 31, 2010
    1

    [...] http://blog.ropardo.ro/2010/07/30/porting-applications-from-oracle-to-postgresql/ July 30, 2010   //   Oracle, PostgreSQL   //   No Comments   //   [...]

  • WP Themes
    August 10, 2010
    2

    Good dispatch and this mail helped me alot in my college assignement. Thanks you as your information.

  • Free Wordpress Themes
    September 25, 2010
    3

    Nice fill someone in on and this mail helped me alot in my college assignement. Gratefulness you as your information.

Leave a Reply

 


  • « Previous post
  • Next post »
  • Recent Posts

    • Installing PyGraphviz on Windows
    • Convert python object to XML representation
    • Liferay Portlet Development
    • Norway Road Show 2011 private meeting invitation
    • Oracle OpenWorld 2011
  • Ropardo is Hiring

  • Subscribe

    • Add to Google Reader or Homepage Add to netvibes TopOfBlogs
  • Recent Comments

    • Rajkumar Pomaji on Bluetooth PC Remote Control
    • Stelian Morariu on GWT 2.1 – Uploading a file using the RPC mechanism
    • Sergio on GWT 2.1 – Uploading a file using the RPC mechanism
    • Artem on Liferay: Deployment will start in a few seconds… and how to realy start
    • rkd80 on GWT 2.1 – Uploading a file using the RPC mechanism
  • Archives

    • November 2011 (1)
    • September 2011 (4)
    • July 2011 (3)
    • June 2011 (2)
    • May 2011 (4)
    • April 2011 (4)
    • March 2011 (3)
    • February 2011 (2)
    • January 2011 (2)
    • December 2010 (1)
    • November 2010 (4)
    • October 2010 (4)
    • August 2010 (3)
    • July 2010 (3)
    • June 2010 (6)
    • May 2010 (8)
    • April 2010 (7)
    • March 2010 (9)
    • February 2010 (6)
    • January 2010 (5)
    • December 2009 (7)
    • November 2009 (9)
    • October 2009 (10)
    • September 2009 (14)
    • August 2009 (10)
    • July 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (1)
    • March 2009 (1)
    • October 2008 (3)
    • October 2007 (3)
    • July 2007 (4)
    • June 2007 (1)
    • May 2007 (3)
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Categories

    • News (15)
    • Ropardo Team (8)
    • Ropardo Products (6)
      • File Tracking Client (4)
      • iManagement (2)
    • Software Development (83)
      • Microsoft.NET (22)
      • Java (40)
      • Oracle (8)
      • Power Builder (3)
      • Liferay (5)
      • Lotus Notes (9)
      • xWiki (4)
    • System Adminstration (13)
      • Linux (10)
      • Windows (3)
    • Programming (1)
    • Uncategorized (3)
    • Databases (10)
      • MSSQL (5)
      • PostgreeSQL (3)
    • Microsoft.NET (1)
    • Web Development (28)
      • ASP/ASPX (3)
      • Content Management Systems (1)
      • HTML/CSS (5)
      • Javascrip/AJAX (8)
      • PHP (7)
    • Oracle E Business Suite (6)
  • Tags

    .NET ajax blog C# certification client CMS control css database Debugging django Domino Eclipse extension file tracking filter fun gentoo google Hibernate how to html image iManagement import Java javascript jQuery liferay Linux Lotus Notes lotus script Oracle Oracle BI Publisher 11g PHP portal PostgreSQL powerbuilder Python SQL Telerik velocity xml Xwiki

© 2010 ROPARDO s.r.l..

Powered by WordPress. Styled by Ropardo