query cp user to partner

mail@pastecode.io avatar
unknown
pgsql
14 days ago
961 B
5
Indexable
Never
INSERT INTO partners (
    email,
    name,
    password,
    role,
    profile,
    agent_id,
    "createdAt",
    "updatedAt",
    phone
)
SELECT
    a.email,          -- Email dari tabel agents
    a.pic_name,       -- Nama dari tabel agents
    NULL,             -- Password, bisa diisi NULL atau nilai default
    '1',   -- Role, isi dengan nilai default atau sesuai kebutuhan
    NULL,             -- Profile, bisa diisi NULL atau nilai default
    a.id,             -- Agent ID dari tabel agents
    a."createdAt",    -- Tanggal pembuatan dari tabel agents
    a."updatedAt",    -- Tanggal pembaruan dari tabel agents
    a.phone          -- Nomor telepon dari tabel agents
FROM
    agents a
WHERE
    a.type_agent = 2;

update partners p
set password = (select password from users u where u.email = p.email)
where password is null;

delete
from users
where email in (select email from agents where agents.email = users.email and agents.type_agent = 2);
Leave a Comment