Can't filter by uuid...
Hey all!
Trying to GET a table using .eq() filter.
The column I want to get is the type of uuid and it's a foreign key for another table.
Every other filter does work, but it's crucial for me to get it done by filtering by this uuid.
I've tried everything: even putting a string manually into .eq() didn't work.
In the console I'm getting err 400.
RLS are disabled in both tables.
Any ideas?
48 Replies
You are going to need to provide some code samples, url from developer console if you can and your table and key column name/type.
You have not given enough info to help you.
Sure!
It looks like I am not able to attach screenshots here.
This code doesn't work:
This code does work:
My table structure is the following:
id -> uuid
created_at -> timestamp
from -> text
to -> uuid (foreign key for another table with users)
amount -> float8
transaction_hash -> text
message -> text
Basically I can filter by every parameter but the column 'to'.
Url from the dev console is
https://ykrdpfyfwvzazyztjbzt.supabase.co/rest/v1/donations?select=*&is=eq.38c71ccf-4d75-4a53-af24-65dae701f174
for example.I'm using useEffect in react, the whole snippet works well in other places:
The word 'to' doesn't mean anything
The way .eq works is it compares the first parm to the second and returns true if they're equal. So if you have the ability to pass your userID via a parm you can check it like .eq(userIdFromParm, 'id')
I'm trying to filter by the 'to' column?
Oh I see
Where is the variable id coming from in your code, the second parm inside .eq?
It's a prop, shouldn't have issues as it's being printed in the console before I run the snippet...
Also if your to column is storing the UUIDs make sure that you didn't select text as the type inside postgres, it should be the same type 'UUID'
Gotcha
So your url makes no sense.
select=*&is=eq.38c71ccf-4d75-4a53-af24-65dae701f174
&is=
is saying your column is named is
....This doesn't work either
https://ykrdpfyfwvzazyztjbzt.supabase.co/rest/v1/donations?select=*&to=eq.38c71ccf-4d75-4a53-af24-65dae701f174
messages?select=*&id=eq.75
Is from a working select with.eq in my test environment.
Is the is
something we need to understand, or did you rename/user another column?No, I think I was just trying different options, we can disregard that - there is no is column
Is there any more error info in the response? Normally if nothing is found you get an empty array back. Not a 400 error.
It looks like I'm only getting any data if I'm filtering by any other column - getting error when trying to filter by id.
It was all fine in the previous build when the id column was just an id, not uuid.
What does "previous build mean?" Did you change the column type after it was set up as int type?
No, I had different databases with id's with the type of 'id' which I then deleted and created the same databases with the id's with the types of 'uuid'.
I'm able to get list of users by uuid for example, but not donations.
I would expect something an error message back with something about column not matching.
If you enter a number instead of uuid does it come back without error?
Can you do a simple select(*) and does it return UUIDs?
Without the filter
For example, this code works:
Something is wrong with your column type, or the cache. For sure eq works with UUID.
yeah I've used it before too Gary
Yes it does
Example, the profiles table created from user management started, I constantly query it with UUID
It works for me on one page too, but not on the other one... How do I deal with cache?
Can you run this in the sql editor:
NOTIFY pgrst, 'reload schema';
And you have not said if you get an error message.
What does this mean? And what cache are you referring to?
You wrote that something might be wrong with my cache
Success. No rows returned
All I'm getting in the console is this:
GET https://ykrdpfyfwvzazyztjbzt.supabase.co/rest/v1/donations?select=*&to=eq.38c71ccf-4d75-4a53-af24-65dae701f174 400
What are data and error?
On the cache, that was the SQL command I sent to clear the API's schema cache. Sometimes if you have a table, then change a column type or foreign keys you have to reload it.
Getting this https://codeshare.io/N3Mpjm
What is that?
Error in my console
The error from supabase select ?
Yes. When I'm sending GET request, this is what I'm getting in the console.
{data, error} = await supabase....
That error is what I'm asking for, and you have it called err which won't work.
and is data null or
[]
?I'm not sure that this is the {error}, just a default fetch error.
Yesh, I'm struggling to understand why.
You need to change {data, err} to {data,error:err}
Oh
Did you run the SQL command I showed?
That error is the key.
Yes, I have. I didn't see it earlier.
It says your column is or the API thinks it is an int8 column
Can you show a pic of your table column in the table UI?
This is my user database:
https://snipboard.io/Yyldoh.jpg
This is my donations database:
https://snipboard.io/ZEkPqh.jpg
Can you show the actual to column in editor?
Also, I hate to ask this.... Any chance your code is going to a different instance (like your old one) instead of the one you are showing?
Users: https://snipboard.io/hQB2e4.jpg
Donations: https://snipboard.io/Jja8qy.jpg
Everything is possible...
No, I tried everything to check, it does talk to a new instance of my database. It shows data from a new database when I filter by any other column
I'm out of ideas. For some reason the API thinks you have int8 column, but the UI is showing a uuid column.
Ok, gotcha.
At least now I know what the error is, didn't know I had a bug in my code! Thanks a lot for that, I won't be taking your time!
You could just delete the column, create a new one. First without the fk link, then with.
LOL. Simply renaming the database worked.
I'm speechless.
Thanks a lot for your help! 🙏
Some sort of caching thing likely.