jaitaiwan
05/17/2022, 6:38 AM'admin' = any(select roles from public.users_orgs where user_id = auth.uid() and org_id = orgs.id limit 1)
and I'm having all sorts of trouble. roles
is a text[]
AndreSe_
05/18/2022, 2:16 AMSteve
05/31/2022, 4:21 PMWHERE id IS NULL OR tb1.id = id
jaitaiwan
05/18/2022, 11:49 PMcreate or replace function public.user_orgs() returns uuid[] as $$
select array_agg(org_id) from users_orgs where user_id = auth.uid() limit 1;
$$ language sql stable;
And the RLS policy has a WITH CHECK
that I'm trying to make work like this:
"admin" in (select roles from users_orgs where user_id = auth.uid() and org_id = orgs.id)
If I use admin in "
quotes it interprets it as a column name and if I use '
quotes it has a malformed array error.sylar815
05/19/2022, 6:11 AMSELECT branchcode, valuein from daily WHERE CAST(datetime AS DATE) = {{date1.value}} ORDER BY "branchcode" ASC
query2
select branchcode, sum(valuein) as my_sum from daily where datetime between {{moment(date1.value).format("YYYY-MM-DD")}} and {{moment(date1.value).add(6, 'DAYS').format("YYYY-MM-DD")}} group by branchcode ORDER BY "branchcode" ASC
Desired output column-wise
branchcode, valuein, my_sum
i tried using WITH, and subquery - but ran out of luck.
thanks in advance.d33pu
05/19/2022, 9:27 AMd33pu
05/19/2022, 10:21 AMSacha
05/19/2022, 8:22 PMjaitaiwan
05/20/2022, 9:29 AMCREATE or REPLACE function auth.update_token() RETURNS TRIGGER AS $$
DECLARE
alias text;
BEGIN
SELECT "public"."orgs".alias into alias from "public"."orgs" WHERE id = new.org_id;
UPDATE users SET raw_app_meta_data = jsonb_set(raw_app_meta_data, ARRAY['roles', NEW.org_id::text], to_jsonb(NEW.roles)) WHERE id = NEW.user_id;
IF trim(alias) <> '' THEN
UPDATE users SET raw_app_meta_data = jsonb_set(raw_app_meta_data, ARRAY['roles', alias], to_jsonb(NEW.roles)) WHERE id = NEW.user_id;
END IF;
RETURN NEW;
END;
$$ language plpgsql;
And a trigger:
CREATE TRIGGER "Update token with allowed orgs" AFTER INSERT OR UPDATE
ON "public"."users_orgs"
FOR EACH ROW EXECUTE PROCEDURE auth.update_token();
But the trigger doesn't seem to be running the updates 🤷♂️jaitaiwan
05/20/2022, 10:51 AMuskolol
05/20/2022, 11:53 AMavalanche
05/20/2022, 1:19 PMsql
create or replace function search_items(lang regconfig, query text)
returns table (title text, description text)
language plpgsql
as
$$
declare
query_vector tsquery = to_tsquery(lang, query);
begin
return query
select
item.title,
item.description
from item
where (setweight(to_tsvector(lang, item.title), 'A') || ' ' ||
setweight(to_tsvector(lang, item.description), 'B')) @@ query_vector
order by ts_rank((setweight(to_tsvector(lang, item.title), 'A') || ' ' ||
setweight(to_tsvector(lang, item.description), 'B')), query_vector)
desc;
end;
$$;
sylar815
05/20/2022, 1:46 PMSacha
05/21/2022, 4:37 PMgaryaustin
05/21/2022, 6:19 PMLudvig
05/22/2022, 2:51 PMMuezz
05/22/2022, 5:50 PMLudvig
05/22/2022, 8:38 PMgaryaustin
05/22/2022, 9:05 PMAlanK
05/24/2022, 11:14 PMconst { data: profileHazards, error } = await db
.from('profile')
.select(
'site_hazards,other_site_hazards,land_adjacent_hazard,other_hazards'
)
.eq('id', _session.user.id);
old_zoomer🇺🇦
05/25/2022, 7:20 PMpostgres=> ALTER TABLE "blocks" ADD COLUMN "textSearch" TSVECTOR GENERATED
ALWAYS AS (to_tsvector('english', text)) STORED;
ERROR: could not extend file "base/12974/446445": No space left on device
HINT: Check free disk space.
burggraf
05/25/2022, 7:45 PMNicmeisteR
05/26/2022, 8:44 AMjson
{
"foo": {
"bar": {
"baz": 50
},
"something": null
}
}
NicmeisteR
05/26/2022, 9:05 AMDanMossa
05/29/2022, 1:01 AMauth.uid()
is user_id_one
OR user_id_two
garyaustin
05/29/2022, 1:22 AMSteve
05/31/2022, 4:21 PMVik
06/02/2022, 12:02 AMasleepingpanda
06/02/2022, 2:05 PMeTsiE3tmnI4
for example).
The function is run as the default value on a column in my dB
I'm getting some kind of syntax error, but there are little to no details in the error. Does anybody see anything wrong with it?? Thanks!!
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
CREATE OR REPLACE FUNCTION generate_shortkey()
RETURNS TEXT AS
$$
DECLARE
gkey TEXT;
key TEXT;
qry TEXT;
found TEXT;
BEGIN
-- generate the first part of a query as a string with safely
-- escaped table name, using || to concat the parts
qry := 'SELECT shortkey FROM ' || quote_ident(TG_TABLE_NAME) || ' WHERE shortkey=';
LOOP
-- 8 bytes gives a collision p = .5 after 5.1 x 10^9 values
gkey := encode(gen_random_bytes(8), 'base64');
gkey := replace(gkey, '/', '_'); -- url safe replacement
gkey := replace(gkey, '+', '-'); -- url safe replacement
key := rtrim(gkey, '='); -- cut off padding
-- Concat the generated key (safely quoted) with the generated query
-- and run it.
-- SELECT id FROM "test" WHERE id='blahblah' INTO found
-- Now "found" will be the duplicated id or NULL.
EXECUTE qry || quote_literal(key) INTO found;
-- Check to see if found is NULL.
-- If we checked to see if found = NULL it would always be FALSE
-- because (NULL = NULL) is always FALSE.
IF found IS NULL THEN
-- If we didn't find a collision then leave the LOOP.
EXIT;
END IF;
-- We haven't EXITed yet, so return to the top of the LOOP
-- and try again.
END LOOP;
RETURN key
END
$$ language 'plpgsql';
garyaustin
06/02/2022, 2:16 PM