Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table target ( id serial, val text, primary key (id), unique (val) ); -- Вставляем Раз и Два insert into target (val) values ('One'), ('Two'); create table source ( id serial, val text, primary key (id), unique (val) ); -- Вставляем Раз и Два insert into source (val) values ('One'), ('Three'); -- Ошибочка insert into target (val) select val from source; -- Попробуем так insert into target (val) select val from source on conflict (val) do nothing; select * from target; create table target2 ( id serial, val text, primary key (id), unique (val) ); -- Вставляем Раз и Два insert into target2 (val) values ('One'), ('Two'); insert into target2 (val) select val from source where not exists (select true from target2 where target2.val = source.val); select * from target2; create table target3 ( id serial, val text, primary key (id), unique (val) ); -- Вставляем Раз и Два insert into target3 (val) values ('One'), ('Two'); merge into target3 t using source s on t.val = s.val when not matched then insert (val) values (val); select * from target3;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear