<s>
A	O
relational	B-Application
database	I-Application
management	I-Application
system	I-Application
uses	O
SQL	B-Language
(	O
also	O
called	O
upsert	B-Language
)	O
statements	O
to	O
INSERT	B-Language
new	O
records	O
or	O
UPDATE	B-Language
existing	O
records	O
depending	O
on	O
whether	O
condition	B-Language
matches	O
.	O
</s>
<s>
It	O
was	O
officially	O
introduced	O
in	O
the	O
SQL:2003	B-Language
standard	O
,	O
and	O
expanded	O
in	O
the	O
SQL:2008	B-Language
standard	O
.	O
</s>
<s>
A	O
right	O
join	O
is	O
employed	O
over	O
the	O
Target	O
(	O
the	O
INTO	O
table	O
)	O
and	O
the	O
Source	O
(	O
the	O
USING	O
table	O
/	O
view	O
/	O
sub-query	O
)	O
--where	O
Target	O
is	O
the	O
left	O
table	O
and	O
Source	O
is	O
the	O
right	O
one	O
.	O
</s>
<s>
If	O
multiple	O
Source	O
rows	O
match	O
a	O
given	O
Target	O
row	O
,	O
an	O
error	O
is	O
mandated	O
by	O
SQL:2003	B-Language
standards	O
.	O
</s>
<s>
Database	O
management	O
systems	O
PostgreSQL	B-Application
,	O
Oracle	B-General_Concept
Database	I-General_Concept
,	O
IBM	B-Application
Db2	I-Application
,	O
Teradata	O
,	O
EXASOL	O
,	O
Firebird	B-Application
,	O
CUBRID	B-Application
,	O
H2	B-Language
,	O
HSQLDB	B-Application
,	O
MS	B-Application
SQL	I-Application
,	O
Vectorwise	B-Application
and	O
Apache	B-Language
Derby	I-Language
support	O
the	O
standard	O
syntax	O
.	O
</s>
<s>
Some	O
also	O
add	O
non-standard	O
SQL	B-Language
extensions	O
.	O
</s>
<s>
Some	O
database	O
implementations	O
adopted	O
the	O
term	O
"	O
Upsert	B-Language
"	O
(	O
a	O
portmanteau	O
of	O
update	B-Language
and	O
insert	B-Language
)	O
to	O
a	O
database	O
statement	O
,	O
or	O
combination	O
of	O
statements	O
,	O
that	O
inserts	B-Language
a	O
record	O
to	O
a	O
table	O
in	O
a	O
database	O
if	O
the	O
record	O
does	O
not	O
exist	O
or	O
,	O
if	O
the	O
record	O
already	O
exists	O
,	O
updates	O
the	O
existing	O
record	O
.	O
</s>
<s>
This	O
synonym	O
is	O
used	O
in	O
PostgreSQL	B-Application
(	O
v9.5	O
+	O
)	O
and	O
SQLite	B-Language
(	O
v3.24	O
+	O
)	O
.	O
</s>
<s>
It	O
is	O
also	O
used	O
to	O
abbreviate	O
the	O
"	O
MERGE	B-Language
"	O
equivalent	O
pseudo-code	O
.	O
</s>
<s>
It	O
is	O
used	O
in	O
Microsoft	B-Application
Azure	I-Application
SQL	I-Application
Database	I-Application
.	O
</s>
<s>
Some	O
other	O
database	O
management	O
systems	O
support	O
this	O
,	O
or	O
very	O
similar	O
behavior	O
,	O
through	O
their	O
own	O
,	O
non-standard	O
SQL	B-Language
extensions	O
.	O
</s>
<s>
MySQL	B-Application
,	O
for	O
example	O
,	O
supports	O
the	O
use	O
of	O
syntax	O
which	O
can	O
be	O
used	O
to	O
achieve	O
a	O
similar	O
effect	O
with	O
the	O
limitation	O
that	O
the	O
join	O
between	O
target	O
and	O
source	O
has	O
to	O
be	O
made	O
only	O
on	O
PRIMARY	O
KEY	O
or	O
UNIQUE	O
constraints	O
,	O
which	O
is	O
not	O
required	O
in	O
the	O
ANSI/ISO	O
standard	O
.	O
</s>
<s>
It	O
also	O
supports	O
syntax	O
,	O
which	O
first	O
attempts	O
an	O
insert	B-Language
,	O
and	O
if	O
that	O
fails	O
,	O
deletes	O
the	O
row	O
,	O
if	O
exists	O
,	O
and	O
then	O
inserts	B-Language
the	O
new	O
one	O
.	O
</s>
<s>
SQLite	B-Language
's	O
works	O
similarly	O
.	O
</s>
<s>
It	O
also	O
supports	O
as	O
an	O
alias	O
for	O
compatibility	O
with	O
MySQL	B-Application
.	O
</s>
<s>
Firebird	B-Application
supports	O
though	O
fails	O
to	O
throw	O
an	O
error	O
when	O
there	O
are	O
multiple	O
Source	O
data	O
rows	O
.	O
</s>
<s>
Additionally	O
there	O
is	O
a	O
single-row	O
version	O
,	O
,	O
but	O
the	O
latter	O
does	O
not	O
give	O
you	O
the	O
option	O
to	O
take	O
different	O
actions	O
on	O
insert	B-Language
versus	O
update	B-Language
(	O
e.g.	O
</s>
<s>
IBM	B-Application
Db2	I-Application
extends	O
the	O
syntax	O
with	O
multiple	O
and	O
clauses	O
,	O
distinguishing	O
them	O
with	O
guards	B-Language
.	O
</s>
<s>
Microsoft	B-Application
SQL	I-Application
Server	I-Application
extends	O
with	O
supporting	O
guards	B-Language
and	O
also	O
with	O
supporting	O
Left	O
Join	O
via	O
clauses	O
.	O
</s>
<s>
PostgreSQL	B-Application
supports	O
merge	B-Language
since	O
version	O
15	O
but	O
previously	O
supported	O
merging	O
via	O
.	O
</s>
<s>
CUBRID	B-Application
supports	O
statement	O
.	O
</s>
<s>
It	O
also	O
supports	O
for	O
compatibility	O
with	O
MySQL	B-Application
.	O
</s>
<s>
Apache	B-Application
Phoenix	I-Application
supports	O
and	O
UPSERT	B-Language
SELECT	O
syntax	O
.	O
</s>
<s>
Spark	O
SQL	B-Language
supports	O
and	O
clauses	O
in	O
actions	O
.	O
</s>
<s>
Apache	B-Language
Impala	I-Language
supports	O
.	O
</s>
<s>
A	O
similar	O
concept	O
is	O
applied	O
in	O
some	O
NoSQL	B-General_Concept
databases	O
.	O
</s>
<s>
in	O
MongoDB	B-Application
the	O
fields	O
in	O
a	O
value	O
associated	O
with	O
a	O
key	O
can	O
be	O
updated	O
with	O
an	O
operation	O
.	O
</s>
<s>
In	O
Redis	B-Operating_System
the	O
operations	O
sets	O
the	O
value	O
associated	O
with	O
a	O
given	O
key	O
.	O
</s>
<s>
Redis	B-Operating_System
does	O
not	O
know	O
any	O
detail	O
of	O
the	O
internal	O
structure	O
of	O
the	O
value	O
,	O
so	O
an	O
update	B-Language
would	O
have	O
no	O
meaning	O
.	O
</s>
