Denzo
01/13/2022, 4:59 PMDenzo
01/13/2022, 5:00 PMsql
create or replace function link_cosmos_userid()
returns trigger
language plpgsql
as $$
begin
update auth.users
set raw_user_meta_data = jsonb_set(raw_user_meta_data, '{cosmos_userid}', get_cosmos_userid(new.email), true)
where users.id = new.id
end;
$$;
chipilov
01/13/2022, 5:35 PMFreakDJ
01/15/2022, 12:32 AMselect fetch_data()
it says "structure of query does not match function result type"
create or replace function fetch_data()
returns setof "SolanaFloorTracker"
language plpgsql
as $$
begin
return query
SELECT rank_filter.*
FROM (
SELECT "SolanaFloorTracker".*,
rank() OVER (
PARTITION BY "CollectionName"
ORDER BY created_at DESC
)
FROM "SolanaFloorTracker"
) rank_filter WHERE RANK <=2;
end;
$$
I also tried returns setof record
but the output is set-valued function called in context that cannot accept a set. I tested the inner SQL query and it works, so I think I just need to learn about what I need to return to get this to work properly?garyaustin
01/15/2022, 12:55 AMtourdownunder
01/15/2022, 9:37 PMmwit
01/15/2022, 10:43 PMsql
SELECT
g.user_id,
(select curRank+1 into curRank) rank1
FROM
(
SELECT
p.user_id
FROM posts p
WHERE p.parent_uuid = input_uuid
OR p.uuid = input_uuid
GROUP BY p.user_id
) g
SELECT ... INTO is not allowed here
curRank is the issue here, any ideas π€ ?astronautical
01/15/2022, 11:24 PMCREATE TABLE posts (
id bigint generated by default as identity primary key,
user_id uuid references auth.users not null,
user_email text,
title text,
content text,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
alter table posts enable row level security;
create policy "Individuals can create posts." on posts for
insert with check (auth.uid() = user_id);
create policy "Individuals can update their own posts." on posts for
update using (auth.uid() = user_id);
create policy "Individuals can delete their own posts." on posts for
delete using (auth.uid() = user_id);
create policy "Posts are public." on posts for
select using (true);
I need a straight-to-the-point guide to the query formats for Supabase. I wasn't able to figure out what to look for. Thanks.garyaustin
01/15/2022, 11:40 PMastronautical
01/15/2022, 11:50 PMgaryaustin
01/15/2022, 11:56 PMastronautical
01/16/2022, 12:53 AMcharles.morrow
01/18/2022, 2:23 PMconst { data, error } = await supabaseClient
.from('treasure_hunt')
.update({
trigger: triggerIds,
})
.eq('uuid', id);
but it doesnt work as expected.
Instead I am just "brute forcing it" by deleting existing links and recreating the new links
await supabaseClient
.from<definitions['trigger_treasure_hunt_link']>(
'trigger_treasure_hunt_link'
)
.delete()
.match({ treasure_hunt_uuid: id });
const { data, error } = await supabaseClient
.from('trigger_treasure_hunt_link')
.insert(
triggerIds.map((trigger) => ({
treasure_hunt_uuid: id,
trigger_uuid: trigger,
}))
);
Is there a smart way to do this like query 1?
Thanksjason-lynx
01/19/2022, 3:16 AMThePhilip
01/21/2022, 1:26 AMScott P
01/21/2022, 1:57 AMDenzo
01/21/2022, 9:49 AMsql
update auth.users
set raw_user_meta_data = jsonb_set('{}', '{cosmos_userid}', public.get_cosmos_userid(email))
where email = 'my_private@email.address'
returning email, raw_user_meta_data;
but this does not:
sql
create or replace function public.link_cosmos_userid()
returns trigger
language plpgsql
as $$
begin
update auth.users
set raw_user_meta_data = jsonb_set('{}', '{cosmos_userid}', public.get_cosmos_userid(new.email))
where id = new.id;
return new;
end;
$$;
The problem seems to be in the stored procedure call get_cosmos_userid()
. Even if I hardcode the same email address, I get some arcane error that is useless.
If I replace the function call with something like to_jsonb('test'::text)
, the trigger works just fine. But that same function call works just fine when executed outside of the trigger.
Anyone have any idea what the problem might be? Perhaps some incompatibility with SQL and PLPGSQL?Denzo
01/21/2022, 9:50 AMexecute 3: with recursive pks_fks as ( -- pk + fk referencing col select conrelid as resorigtbl, unnest(conkey) as resorigcol from pg_constraint where contype IN ('p', 'f') union -- fk referenced col select confrelid, unnest(confkey) from pg_constraint where contype='f' ), views as ( select c.oid as view_id, n.nspname as view_schema, c.relname as view_name, r.ev_action as view_definition from pg_class c join pg_namespace n on n.oid = c.relnamespace join pg_rewrite r on r.ev_class = c.oid where c.relkind in ('v', 'm') and n.nspname = ANY($1 || $2) ), ...........
ziad
01/21/2022, 5:46 PMsylar815
01/24/2022, 6:42 AMSealion
01/24/2022, 9:23 PMmoein
01/25/2022, 8:08 PMTremalJack
01/25/2022, 8:39 PMCREATE EXTENSION IF NOT EXISTS postgis
SCHEMA extensions
VERSION "3.1.4";
To generate the schema then Im enable to add the DDL to generate the views: geography_columns
and geometry_columns
But Im not sure if it's all here... I need add more?Just a Normal Guy
01/26/2022, 3:07 AMcollections
2. user_collections
(join table between the two and gives a user access to a collection
I've setup RLS such that
+ select
is only for collections
where there's a user_collections.collections_id = collections.id AND user_collections.user_id = user.id
which is working
+ insert
is only for authenticated
users since I want to let anyone do it
The problem is that because insert
seems to use select
I can't actually insert even though my logic seems to be right
The workaround is that I can get insert
to work if I use {returning: "minimal}
so that it doesn't return anything (https://supabase.com/docs/reference/javascript/insert#notes) but then I don't have the id
to create the join table and give permissions for the select
Any thoughts on how to do this correctly? I imagine join table permissions is a very common design that there's probably an elegant solution I'm missinggaryaustin
01/26/2022, 4:02 AMsilentworks
01/26/2022, 2:54 PMJust a Normal Guy
01/26/2022, 3:06 PMjaf
01/26/2022, 6:26 PMjavascript
const { data, error } = await db
.from('source_products')
.select('*, source_products!inner(*)')
.eq('id', id)
.eq('source_products.main_sku', 'how do I reference this')
.limit(1)
.maybeSingle()
Basically I want to join in other products that have the same value for main_sku
. Do I need to alias both 'tables' (it's the same table of course)
This works:
sql
select t1.*, t2.* from source_products t1 left join source_products t2 on t1.main_sku = t2.main_sku where t1.id = '4bfbf03d-9707-4b03-ac44-04fb7296a91a'
How do I do the same with supabase-js?Steve
01/26/2022, 10:28 PMdouglasjarquin
01/28/2022, 2:26 PM