! Do you even Vim, bro?
07/05/2022, 10:01 PMsets
and queries
. Maybe they're the things I desperately need. I don't know! 🙏
sql
create or replace function get_random_prices()
returns table (item_id int, value int)
as $$
declare
random_prices table (item_id int, value int);
begin
select id, floor(random() * (max_value - min_value + 1) + min_value)
insert into random_prices
as value
from prices_ranges; -- private table, no policies set
return random_prices;
end
$$ language plpgsql;
garyaustin
07/06/2022, 12:23 AMgaryaustin
07/06/2022, 12:24 AM! Do you even Vim, bro?
07/06/2022, 1:04 PMprivate
table called prices_ranges
. I want all of the ranges to stay private, no one should be able to access them at any time, outside of me in my Supabase panel, of course. What I also want is an rpc
that can be called from within my React application so that the user receives just the randomly generated values and has no knowledge about the ranges whatsoever.! Do you even Vim, bro?
07/06/2022, 1:14 PMsql
create or replace function get_random_prices()
returns table (item_id int, value int)
as $$
begin
return query
select
id::int as item_id,
floor(random() * (max_value - min_value + 1) + min_value)::int as value
from prices_ranges;
end
$$ language plpgsql;
But it still cannot be accessed 😦! Do you even Vim, bro?
07/06/2022, 1:16 PMgaryaustin
07/06/2022, 1:47 PM! Do you even Vim, bro?
07/06/2022, 4:36 PMprices_ranges
because it has RLS on. Correct?garyaustin
07/06/2022, 4:54 PMgaryaustin
07/06/2022, 4:58 PM