#mysql
1 messages · Page 1 of 1 (latest)
just write out the code
if user_id in claim_stats:
count = count + 1
else:
await cursor.execute('SQL command')
something like that would be it
noo
?
i want to to this in a mysql string
wdym?
like mycursor.execute("if UserID in ClaimStats exists then update Count=Count+1 else insert into Claimstats UserID, Count=1")
i tried things like:
mycursor.execute("INSERT INTO ClaimStats (UserID, Count) VALUES (%s,%s) ON DUPLICATE KEY UPDATE Count=Count+1", (user.id, 1))
why not do the checks within python and then use SQL when you want to insert
you can use upsert
this doesn't work?
i cleared the claimstats
then i executed it and it inserted the user.id and 1
then i did it again
and it not updated it to Count+1
it inserted it again
can you run show indexes from ClaimStats
so there's no indexes
you need to create an index if you expect ON DUPLICATE KEY to do anything
how to?
using the create index command
or when you create the table, mark the column as a primary key and it'll create the index for you
i dont understand
you should do some research on mysql then
@pastel dock ALTER TABLE ClaimStats ADD PRIMARY KEY (UserID)
Then INSERT INTO ClaimStats (UserID, Count) VALUES (%s,%s) ON DUPLICATE KEY UPDATE Count=Count+1", (user.id, 1) will work