why i have this error ```sql select * from storag...
# sql
r
why i have this error
Copy code
sql
select * from storage.buckets.id = "hiking-picture"::text
``Failed to validate sql query: syntax error at or near "="``
g
Postgres uses single quotes only for strings.
v
Doesn't need the dot to be replaced with
where
g
The whole thing seems a mess....
select * from storage.buckets where id = 'hiking-picture'
works without ::text but does not hurt to add it.
Also not really sure what is useful in that row for you. It is just the bucket name and whether it is public or not.
r
@garyaustin because if i understand what wrong with this simple query i can understand what this
Copy code
sql
create policy insert_as_admin ON storage.buckets.id = 'hiking-picture'::text for all using (
(EXISTS ( SELECT 1
   FROM profiles
  WHERE ((profiles.admin IS TRUE) AND (profiles.id = 'bi215-8e02-6c3f13e05026'::uuid))))
);`
do not pass work
g
I have no idea what you are trying to do with that... If you want to insert files into a "bucket" you need to set policy on the storage.object table like: https://supabase.com/docs/guides/storage#allow-logged-in-access-to-a-bucket Only for insert
Are you using a hosted instance?
r
it was modified whit what you teach me but still syntax error at where
Copy code
sql
create policy insert_as_admin ON storage.buckets WHERE id = 'hiking-picture' for all using(
  exists(select 1 from profiles WHERE profiles.admin is true)
)
if i want all right
g
that is not how you set a policy. You were showing a select.
r
insert update delete etc
g
Can you use the storage UI on an SB instance or are you on your own hosted platform?
r
sb instance ?
i can use storage ui
g
From that link you would use this for all from signed in users
Copy code
create policy "Restricted Access"
on storage.objects for all
using (
  bucket_id = 'hiking-picture'
  and auth.role() = 'authenticated'
);
You would then modify the and to be your exists part.
The storage UI policy part does all the overhead for you... You just deal with the actual sql then.
What I just showed is setting it up on your own with the sql editor.
r
ok ok but i tried sql editor for learning purpose. if i get it i could add more complex sql query
g
So try what I showed you and see if you can upload then change the auth.role() part to be your exists statement (or what ever ends up working for your desire) using ALTER POLICY
Besides knowing what table to be working with (storage.objects) everything else is standard Postgres RLS policy. https://www.postgresql.org/docs/current/sql-createpolicy.html
There are tutorials on policies and RLS for postgres in general on the web in addition to the SB guides.
r
thank you guys