yes thats what I am doing but now I want to do ups...
# off-topic
a
yes thats what I am doing but now I want to do upsert and in docs it mentioned id i.e primary key should be included in data payload. I have table with columns: id(primary key), user_id, access_token now I only want to insert when for that user_id access_token is not present if that row is already present then instead of adding new row I want to only update the access token field for that user_id how can do that using upsert? Note: id is primary key auto generated uuidv4
s
Pass a value, it'll update. Don't pass a value, it'll insert. There's really no magic behind it - it depends entirely on your application logic. If the user has an access_token in your application, retrieve and pass the user_id. If not, just don't pass the value.
a
> Pass a value, it'll update. Don't pass a value, it'll insert. In my case I am seeing same user_id having multiple access_tokens so multiple rows present which I don't want I am doing insert operation code:
Copy code
const { error } = await supabase.from('facebook_access_token').insert([{ user_access_token: long_lived_access_token, user_id: userId }]);
This is adding multiple rows in db
I wanted to use upsert here instead of insert. But note here I am not passing id field in data payload because id is auto generated uuidv4
s
If you're seeing multiple rows for the same user, it sounds like you need a unique constraint on the
user_id
field