VARCHAR2 Data Type - Oracle to PostgreSQL Migration

In Oracle, the VARCHAR2(n) data type stores variable-length character strings up to n bytes (default) or characters with the maximum of 4000 or 32767 bytes if MAX_STRING_SIZE initialization parameter is set to EXTENDED (not set by default).

In PostgreSQL, you can use VARCHAR(n) that can store up to 1 GB (bytes).

Oracle:

  CREATE TABLE specs
  (
    note   VARCHAR2(30),
    name VARCHAR2(100 CHAR),
    item   VARCHAR2(50 BYTE)
  );

PostgreSQL:

  CREATE TABLE specs
  (
    note   VARCHAR(30),
    name VARCHAR(100),
    item   VARCHAR(50)
  );

Overview

Conversion summary:

Oracle PostgreSQL
Syntax VARCHAR2(n [CHAR | BYTE]) VARCHAR[(n)]
Parameter n is the number of characters or bytes (default) n is the number of characters
Range 1 ⇐ n ⇐ 4000 or 32767 (if MAX_STRING_SIZE=EXTENDED) 1 ⇐ n ⇐ 10,485,760
Default n must be specified 1 GB

For more information, see Oracle to PostgreSQL Migration.