Sybase ASE to PostgreSQL Migration

SQLines tools help you transfer data, convert database schema (DDL), views, stored procedures, functions, triggers, queries and SQL scripts from SAP Sybase Adaptive Server Enterprise (Sybase ASE) to PostgreSQL.


  • Sybase Adaptive Server Enterprise 16, 15, 12.x and 11.x
  • PostgreSQL 15.x, 14.x, 13.x, 12.x, 11.x, 10.x and 9.x

See also Sybase SQL Anywhere to PostgreSQL Migration.

Sybase ASE to PostgreSQL Migration Tools

Migration Reference

Technical information on migration from Sybase ASE to PostgreSQL:

SQL Language Elements

Converting SQL language elements:

Sybase ASE PostgreSQL
1 string1 + string2 String concatenation string1 || string2

Data Types

Converting data types:

Sybase ASE PostgreSQL
1 BIGDATETIME Date and time with fraction TIMESTAMP
2 BIGINT 64-bit integer BIGINT
3 BIGTIME Time (Hour, minute, second and fraction) TIME
4 BINARY(n) Fixed-length binary data, 1 ⇐ npagesize BYTEA
5 BIT 0 or 1; NULL is not allowed BOOLEAN
6 CHAR(n), CHARACTER(n) Fixed-length string CHAR(n), CHARACTER(n)
7 DATE Date (year, month and day) DATE
8 DATETIME Date and time with fraction TIMESTAMP
9 DECIMAL(p,s), DEC(p,s) Fixed-point number DECIMAL(p,s), DEC(p,s)
10 DOUBLE PRECISION Double-precision floating-point number DOUBLE PRECISION
11 FLOAT(p) Floating-point number DOUBLE PRECISION
12 IMAGE Variable-length binary data, ⇐ 2G BYTEA
13 INT, INTEGER 32-bit integer INT, INTEGER
14 MONEY 64-bit currency amount MONEY
15 NCHAR(n) Fixed-length national character string CHAR(n)
16 NUMERIC(p,s) Fixed-point number NUMERIC(p,s)
17 NVARCHAR(n) Variable-length national character string VARCHAR(n)
18 REAL Single-precision floating-point number REAL
20 SMALLINT 16-bit integer SMALLINT
21 SMALLMONEY 32-bit currency amount MONEY
22 TEXT Variable-length character data, ⇐ 2G TEXT
23 TIME Time (Hour, minute, second and fraction) TIME
24 TINYINT 8-bit unsigned integer, 0 to 255 SMALLINT
25 UNICHAR(n) Fixed-length Unicode string CHAR(n)
26 UNITEXT Variable-length Unicode data, ⇐ 1G TEXT
27 UNIVARCHAR(n) Variable-length Unicode string VARCHAR(n)
28 UNSIGNED BIGINT 64-bit unsigned integer NUMERIC(20)
29 UNSIGNED INT 32-bit unsigned integer NUMERIC(10)
30 UNSIGNED SMALLINT 16-bit unsigned integer NUMERIC(5)
31 VARBINARY(n) Variable-length binary string BYTEA
32 VARCHAR(n) Variable-length string VARCHAR(n)


Converting CREATE TABLE statement keywords and clauses:

Sybase ASE PostgreSQL
1 IDENTITY(start, increment) Identity column GENERATED ALWAYS AS IDENTITY
(START WITH start INCREMENT BY increment)
2 IDENTITY can be defined on DECIMAL/NUMERIC columns Integer columns must be used

Built-in SQL Functions

Converting built-in SQL functions from Sybase ASE to PostgreSQL:

Sybase ASE PostgreSQL
1 CHAR_LENGTH(string) Number of characters in string CHAR_LENGTH(string)
2 CHARINDEX(substring, string) Get substring position in string POSITION(substring IN string)
3 CONVERT(CHAR | VARCHAR, exp) Convert to string TO_CHAR(exp)
4 DATEADD(dd, int, datetime) Add days to datetime datetime + INTERVAL 'int DAY'
DATEADD(dd, exp, datetime) datetime + exp * INTERVAL '1 DAY'
5 GETDATE() Get the current date and time NOW()
6 SUBSTRING(string, start, length) Return substring SUBSTRING(string, start, length)


Converting stored procedures from Sybase ASE to PostgreSQL:

Sybase ASE PostgreSQL
2 If RETURN is not specified RETURNS VOID is added
3 AS Changed AS $$
4 Declarations inside BEGIN block DECLARE block is between AS and BEGIN clauses
5 END End of procedure block END; $$ LANGUAGE plpgsql;

Transact-SQL Statements

Converting procedural Transact-SQL statements used in stored procedures, functions and triggers from Sybase ASE to PostgreSQL:

Variable declaration and assignment:

Sybase ASE PostgreSQL
1 DECLARE @var [AS] datatype(len) [= default] Variable declaration var datatype(len) [:= default];

Flow-of-control statements:

Sybase ASE PostgreSQL
1 IF condition BEGIN … END IF statement IF condition THEN … END IF;
2 WHILE condition BEGIN … END WHILE loop WHILE condition LOOP … END LOOP;

Cursors operations and attributes:

Sybase ASE PostgreSQL
1 CLOSE cur
Close a cursor CLOSE cur;
2 @@SQLSTATUS = 0 Fetch was successful FOUND

System Procedures

Converting system stored procedures from Sybase ASE to PostgreSQL:

Sybase ASE PostgreSQL
1 sp_addtype name, "basetype(len)",
"not null"
Create a user-defined type CREATE DOMAIN name AS basetype(len)
2 sp_bindrule name, "table.column" Assign a rule to a table column ALTER TABLE table ADD CHECK rule_condition

SQL Statements

Converting SQL statements from Sybase ASE to PostgreSQL:

Sybase ASE PostgreSQL
1 CREATE RULE name AS condition Create a domain of acceptable values Converted to a CHECK constraint