Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upsert (update or insert) in Sybase ASE?

I'm writing an application to move data from Oracle to Sybase and need to perform update / insert operations. In Oracle, I'd use MERGE INTO, but it doesn't seem to be available in Sybase (not in ASE, anyway). I know this can be done with multiple statements, but for a couple of reasons, I'm really trying to get this into a single statement.

Any suggestions?

like image 761
Ickster Avatar asked Dec 21 '10 22:12

Ickster


People also ask

What is Upsert merge?

A relational database management system uses SQL MERGE (also called upsert) statements to INSERT new records or UPDATE existing records depending on whether condition matches. It was officially introduced in the SQL:2003 standard, and expanded in the SQL:2008 standard.

What does *= mean in Sybase?

Sybase supports both Transact-SQL and ANSI outer joins. Transact-SQL outer joins use the *= command to indicate a left outer join and the =* command to indicate a right outer join. Transact-SQL outer joins were created by Sybase as part of the Transact-SQL language.

Is Upsert standard SQL?

UPSERT is a special syntax addition to INSERT that causes the INSERT to behave as an UPDATE or a no-op if the INSERT would violate a uniqueness constraint. UPSERT is not standard SQL. UPSERT in SQLite follows the syntax established by PostgreSQL.


2 Answers

Merge exists in SAP ASE 15.7 upwards, as mentioned here and here

Replace / Upsert exists in SAP ASE 16.0 and up.

You'll need to update to access them.

like image 75
user11673175 Avatar answered Oct 01 '22 10:10

user11673175


Maybe it could work. Tested in ASA9.

insert into my_table (columns) on existing update values (values);
like image 22
Fabrício Benvenutti Avatar answered Oct 01 '22 10:10

Fabrício Benvenutti