SKUZZIE
SKUZZIE
DTDrizzle Team
Created by SKUZZIE on 12/14/2023 in #help
Upsert with multi-column unique index?
Oh my gosh I think I figured it out. It's because I had ad_id set as the primary key, but I really want both ad_id and date to be the primary key. The upsert was working, it was erroring when I was creating another record with the same primary key (as it's supposed to). facepalm Thank you for your help @solo @Angelelz !!!
28 replies
DTDrizzle Team
Created by SKUZZIE on 12/14/2023 in #help
Upsert with multi-column unique index?
I was going to try the last two ideas you had, but doing either throws type errors. Are you sure doing that is supported in Drizzle?
28 replies
DTDrizzle Team
Created by SKUZZIE on 12/14/2023 in #help
Upsert with multi-column unique index?
This is the error again:
NeonDbError: db error: ERROR: duplicate key value violates unique constraint "daily_stats_pkey"
DETAIL: Key (ad_id)=(QP1VlfoJo4QQ_XTL) already exists.
NeonDbError: db error: ERROR: duplicate key value violates unique constraint "daily_stats_pkey"
DETAIL: Key (ad_id)=(QP1VlfoJo4QQ_XTL) already exists.
28 replies
DTDrizzle Team
Created by SKUZZIE on 12/14/2023 in #help
Upsert with multi-column unique index?
@solo Unfortunately I'm still getting the same error. This is what I changed my code to:
const date = dayjs().format("YYYY-MM-DD");
...
await db
.insert(dailyStats)
.values({
ad_id: dbAd.id,
date: date,
...dailyStatsInsert,
})
.onConflictDoUpdate({
target: [dailyStats.ad_id, dailyStats.date],
set: dailyStatsInsert,
});
const date = dayjs().format("YYYY-MM-DD");
...
await db
.insert(dailyStats)
.values({
ad_id: dbAd.id,
date: date,
...dailyStatsInsert,
})
.onConflictDoUpdate({
target: [dailyStats.ad_id, dailyStats.date],
set: dailyStatsInsert,
});
28 replies
DTDrizzle Team
Created by SKUZZIE on 12/14/2023 in #help
Upsert with multi-column unique index?
Yeah here's the full error:
NeonDbError: db error: ERROR: duplicate key value violates unique constraint "daily_stats_pkey"
DETAIL: Key (ad_id)=(MGIkhCKqgCE0Ga1J) already exists.
NeonDbError: db error: ERROR: duplicate key value violates unique constraint "daily_stats_pkey"
DETAIL: Key (ad_id)=(MGIkhCKqgCE0Ga1J) already exists.
Let me test without the ISOString, thank you!!
28 replies