mansueli
06/16/2022, 2:03 PMLior539
06/16/2022, 2:05 PMjaitaiwan
06/16/2022, 4:20 PMLior539
06/17/2022, 1:14 PMusers
table. A user has an id
field (foreign key on auth.oid()
) and also a company_id
I want to write a RLP such that a user can select the row for any other user provided they are in the same company (i.e have the same company_id
)
I wrote the following statement, but the problem is that I get an infinite recursion error (which makes sense). Anyone know how I would be able to achieve my desired RLP?
(id = uid()) OR (company_id = ( SELECT users_1.company_id
FROM users users_1
WHERE (users_1.id = uid())
LIMIT 1)))
Lior539
06/17/2022, 2:08 PMLior539
06/17/2022, 2:08 PMgaryaustin
06/17/2022, 2:26 PMJoão Vitor
06/17/2022, 6:53 PMsupabase.from('cart').select('*, items:cart_item(*)')
?edgaras
06/18/2022, 1:11 AMauth.last_sign_in_at
with public.user_details
?garyaustin
06/18/2022, 1:17 AMedgaras
06/18/2022, 1:18 AMedgaras
06/18/2022, 1:22 AMsql
create function public.handle_new_user()
returns trigger as $$
begin
insert into public.users (id)
values (new.id);
return new;
end;
$$ language plpgsql security definer;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.handle_new_user();
jon.m
06/18/2022, 2:52 AMsql
select first_name,
last_name
from users
sql
select
first_name,
last_name
from users
burggraf
06/18/2022, 1:40 PMAlbert [tox/cis]
06/19/2022, 12:58 PMgrsouza
06/21/2022, 1:08 PMjson
{
"message": "new row violates row-level security policy for table \"families\"",
"code": "42501",
"details": null,
"hint": null
}
Only when I create an item using Prefer return=representation
to return the created object, if I perform the POST request without it, it works.
I suppose it's a lack of permissions for selecting. Here is the whole code (https://gist.github.com/grsouza/4d6d0fc25fd69156e2789fe52eafa7ef)garyaustin
06/21/2022, 1:40 PM! Do you even Vim, bro?
06/22/2022, 1:44 PMsum_values
that sums the values in a row and then puts them at the end. Let's say I have a table that looks like this:
sql
id value_1 value_2 result
1 600 300 0
2 400 100 0
3 100 200 0
-- etc.
The end result should look like this:
sql
id value_1 value_2 result
1 600 300 900
2 400 100 500
3 100 200 300
-- etc.
It could be done in sql
or plpgsql
, I guess.
sql
create or replace function sum_values() returns void as $$
-- 1. Select value_1 and value_2 for each row
-- 2. Into each result insert the proper sum
$$ language sql; -- or plpgsql at this point
As a bonus, how could I make it accept the argument of a range and sum the values in that given range? Or for specific ids only?
Thanks in advance, everyone!e0
06/22/2022, 3:25 PMjJ
06/23/2022, 2:06 PMsql
SELECT *
FROM public.articles AS articles
WHERE EXISTS(
SELECT FROM public.articles_filters
WHERE public.articles.id = article_id AND filter_id = 'bfc8c9ca-361c-51d5-be59-e2ce0aa7e6a6'
)
if I use
javascript
.select(`*, articles_filters!inner(*)`)
.eq('articles_filters.filter_id', 'bfc8c9ca-361c-51d5-be59-e2ce0aa7e6a6')
and because of the inner join it only returns the articles with the one articles_filters, while I would like to return with all of them as you do with .select(*, articles_filters(*)
) but with the ability to filter
I tried .filter(), but it seems that I still need to use !inner
Kind regards, Joegaryaustin
06/23/2022, 2:26 PMWishSolidor
06/24/2022, 3:29 AMgaryaustin
06/24/2022, 3:35 AMWishSolidor
06/24/2022, 3:36 AMbaptisteArno
06/24/2022, 5:30 AMsql
begin;
explain (analyze,buffers,timing)
DELETE FROM "public"."Result" WHERE "public"."Result"."id" IN ('cl1iagqm0003109l8pp19c020','cl1ngg8yt066909mp1jbcjf2g','cl1prkyhb107609minrghucq8','cl2uvt3jo064409l7voketuxg','cl1xy5oby075409l42s25q8sc');
rollback;
Is logging:
Delete on "Result" (cost=0.42..26.51 rows=0 width=0) (actual time=4.245..4.246 rows=0 loops=1)
Buffers: shared hit=28 read=9 dirtied=4
-> Index Scan using "Result_pkey" on "Result" (cost=0.42..26.51 rows=5 width=6) (actual time=0.058..4.113 rows=5 loops=1)
Index Cond: (id = ANY ('{cl1iagqm0003109l8pp19c020,cl1ngg8yt066909mp1jbcjf2g,cl1prkyhb107609minrghucq8,cl2uvt3jo064409l7voketuxg,cl1xy5oby075409l42s25q8sc}'::text[]))
Buffers: shared hit=14 read=9
Planning:
Buffers: shared hit=56
Planning Time: 0.425 ms
Trigger for constraint Answer_resultId_fkey: time=6.694 calls=5
Trigger for constraint Log_resultId_fkey: time=632.656 calls=5
Execution Time: 643.656 ms
(11 rows)
So cascades are triggered for Answer
and Log
but for some reason, the Log
trigger takes a ton of time but there are no Logs
to delete in this case
Any idea how I can optimize that?daviscup
06/24/2022, 3:09 PMselect
looking like this:
.select('uid, created_at, text, topic, corrected, option, progress, characters')
Sometimes, the column text
can be several thousands words long. Since I want to store the result of this query in my vue store, i don't want to have huge text
values.
Is it possible to adjust the query that the value of text
is only e.g. 45 characters long?garyaustin
06/24/2022, 3:14 PMdaviscup
06/24/2022, 3:39 PMjJ
06/25/2022, 12:24 PMsql
.select(`*, storage.objects(*)`)
or is it out of reach from the api? I would like to avoid duplicating the metadata, but not too worried.garyaustin
06/25/2022, 12:32 PM