Postgres equivalent of Oracle's VARCHAR2(N CHAR)?

Viewed 1588

We are in the process of migrating our existing Oracle database to Postgres. So far I have found that both VARCHAR2 and NUMBER are not compatible, but have equivalents in VARCHAR and NUMERIC respectively.

However in our schema I can also see we are defining some datatypes using VARCHAR2(31 CHAR). Changing this to VARCHAR(31 CHAR) is not compatible with Postgres, as it gives a syntax error on the CHAR part. Is there an equivalent way to define this using Postgres 12?

1 Answers

Postgres doesn't make a distinction between "char length" and "byte length" when declaring the maximum length of a varchar column.

The limit is always specified as the number of characters.

So the equivalent of Oracle's VARCHAR2(31 CHAR) is VARCHAR(31) in Postgres.

There is however, no equivalent for Oracle's VARCHAR2(31 byte).

Related