Supabase upsert behaviour

I love to work with WeWeb and Supabase.
I created a table in Supabase, which “created_at” column is set “not null”,and “default NOW()”. It isn’t need to be updated.

When I create workflow in WeWeb, do Upsert with Supabase plugin, and unselect “created_at” field. Creating new row works fine.
But when I test updating existing row, this action failed, with message:

Failed :rotating_light:
Error: null value in column “created_at” of relation “qa_question” violates not-null constraint

I think it is strange, or am I strange. Please check it?

Can you check on the network tab of the browser devtool what request is send to Supabase?

This helps?

fs.js:4 POST https://wjvekujepizalwaxubil.supabase.co/rest/v1/qa_question 400
r @ fs.js:4
t..t. @ index.js:87
(匿名) @ instrument.ts:141
fetch @ manager.js:10
fetch @ manager.js:10
then @ manager.js:10
instrument.ts:113 Error: null value in column “created_at” of relation “qa_question” violates not-null constraint
at Object.upsert (manager.js:10:45449)
at async eval (eval at executeCode (index.b9f75a73.js:977:6256), :1:28)
at async executeCode (index.b9f75a73.js:977:6250)
at async _t (index.b9f75a73.js:2454:31872)
(匿名) @ instrument.ts:113
r @ fs.js:4
error @ index.b9f75a73.js:2454
executeCode @ index.b9f75a73.js:977
await in executeCode(非同期)
_t @ index.b9f75a73.js:2454
runTest @ index.b9f75a73.js:2557
(匿名) @ index.b9f75a73.js:2557
(匿名) @ chunk-vendors.fb0bc9c8.js:165
Zi @ chunk-vendors.fb0bc9c8.js:165
eo @ chunk-vendors.fb0bc9c8.js:165
n @ chunk-vendors.fb0bc9c8.js:165
sentryWrapped @ helpers.ts:85
index.b9f75a73.js:2454 Uncaught (in promise) Error: null value in column “created_at” of relation “qa_question” violates not-null constraint
at Object.upsert (manager.js:10:45449)
at async eval (eval at executeCode (index.b9f75a73.js:977:6256), :1:28)
at async executeCode (index.b9f75a73.js:977:6250)
at async _t (index.b9f75a73.js:2454:31872)

Hey,
this is the console log, saying that created_at have a not null constraint.
If you indeed have set it to be allowed to be null on the qa_question table, then the problem may be that we are sending a null parameter.
To see this, you can open the Network tab on the dev tools, and take a look at the api call to supabase that is receiving an error, and check what has been the request.
(Here an example with a request to create a tournament)

This is looking like this



Hi,
Thank you for kindly support. I know. That’s it.

I’m trying to update an existing row, already filled created_at field. In this case, should I change this column to allow null?
Or I should set created_at field same to before updated.

Hi, what do you pass to id? When I pass null, it raises an error the item doesn't exist.

I think you can’t pass null as ID. Just don’t pass the id at all. Or you’ll need to make a function trigger, that adds the ID before running the upsert. Also, if the ID is your PK, something might be wrong, because you should get that it violates non null constraint.

1 Like

Thank you, I’ve checked the best practices and suggestions not to use this option because it wastes resources.

Really depends on the size of the operation. I think that for a few records, if it simplifies you the life, it’s okay :slight_smile: Upserts are a quick way of doing things, but you’re right, not the most efficient

1 Like