Demo, all content is generated
Question

column "userid" does not exist but I can see userId right there in the table

Solved · 1103 views · asked by gabriel_ss · edited

Lovable made tables with camelCase columns (userId, createdAt). The app works. But when I write my own query in the Supabase SQL editor:

select * from orders where userId = '...';
ERROR:  42703: column "userid" does not exist
HINT:  Perhaps you meant to reference the column "orders.userId".

Why is it lowercase in the error?

What I’ve tried

Tried USERID and UserId, same error.

Comment

2 answers

Marked as helpful by the asker
postgres_pete · edited

Postgres lowercases every identifier you don't put in double quotes. userId becomes userid, which doesn't exist, because the column was created with quotes as "userId".

select * from orders where "userId" = '...';

The app works because supabase-js quotes names for you.

Long term I'd rename to snake_case (user_id, created_at), which is the Postgres convention and saves you quotes forever. But that touches every query in the app, so only do it with a plan (and ask Lovable to update all references in the same step), not on a Friday.

Comment
double quotes worked. I'll leave the renaming for now haha gabriel_ss · edited
The HINT line in the error is Postgres being unusually helpful for once. hannah_reyes · edited
rafa_dev · edited

Middle ground: create a view with snake_case names for your own SQL work. The app keeps working and you stop typing quotes.

Comment
didn't know views could do that, nice gabriel_ss · edited