garyaustin
11/28/2021, 5:05 AMKhan W
11/28/2021, 7:27 AMSETY
11/28/2021, 9:16 PMDROP TABLE IF EXISTS public.user_level;
-- A user level can be between 1 and 3.
-- 1 is a basic user
-- 2 is an admin
-- 3 is a super user
CREATE TABLE IF NOT EXISTS public.user_level (
id uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
user_id uuid NOT NULL REFERENCES auth.users(id),
level smallint DEFAULT 1 CHECK (level >= 1 AND level <= 3)
);
DROP TRIGGER IF EXISTS on_user_created_give_level ON auth.users;
DROP FUNCTION IF EXISTS handle_new_user();
CREATE FUNCTION handle_new_user()
LANGUAGE plpgsql
RETURNS trigger
SECURITY DEFINER
AS $$
BEGIN
INSERT INTO public.user_level (user_id, level) VALUES (new.id, 1);
RETURN new;
END;
$$;
CREATE TRIGGER on_user_created_give_level
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE PROCEDURE handle_new_user();
DROP FUNCTION IF EXISTS get_user_level(uuid);
CREATE FUNCTION get_user_level(id uuid)
LANGUAGE plpgsql
AS $$
DECLARE
input_id ALIAS FOR $1;
user_level INTEGER;
BEGIN
SELECT level INTO user_level FROM public.user_level WHERE public.user_level.user_id = input_id;
RETURN user_level;
END;
$$ RETURNS INTEGER;
Getting the error "syntax error at or near "trigger"" But i cant figure out for the life of me what it isSETY
11/28/2021, 9:20 PMSETY
11/28/2021, 9:20 PMSETY
11/28/2021, 9:20 PMSETY
11/28/2021, 9:21 PMSETY
11/28/2021, 9:21 PMkennethcassel
12/02/2021, 5:13 PMScott P
12/02/2021, 5:18 PMjs
const SBClient = createClient(
'https://my_id.supabase.co',
'anon-key',
{
schema: 'information_schema'
}
);
SBClient
.from('tables')
.eq('table_schema', 'public');
The equivalent SQL would be:
sql
SELECT * FROM information_schema.tables
WHERE table_schema = 'public'
kennethcassel
12/02/2021, 5:32 PMfayaz
12/02/2021, 5:52 PMcreate table integrations (
id uuid references auth.users UNIQUE NOT NULL,
updated_at timestamp with time zone,
airtable_key text unique,
upi_handle text unique,
inserted_at timestamp with time zone DEFAULT timezone('utc'::text, now()) NOT NULL,
primary key (id)
);
And the function to create a new row whenever a new user is created.
create function handle_new_user()
returns trigger as $$
begin
insert into integrations (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();
fayaz
12/02/2021, 5:52 PMSteve
12/02/2021, 6:06 PMfayaz
12/02/2021, 6:15 PMDatabase error saving new user
.chipilov
12/02/2021, 8:38 PMEduardo Lopez
12/03/2021, 2:14 AMEduardo Lopez
12/03/2021, 2:45 AMFreakDJ
12/03/2021, 3:02 AMhtml
<tr>
<th>Collection Name</th>
<th>Current Floor Price</th>
<th>Previous Floor Price</th>
<th>Volume</th>
</tr>
So, I need to group by collection name and then order by timestamp and get the two most recent prices to put into the table (current and previous).
What would the SQL for something like this look like? Hopefully I worded this properly enough to portray what I am trying to accomplish!tourdownunder
12/03/2021, 5:48 AMSETY
12/04/2021, 2:41 PMtourdownunder
12/04/2021, 4:51 PMselect version();
to find out next time at a computer.
Edit. My instance is PostgreSQL 13.3
SETY
12/04/2021, 8:27 PMSETY
12/04/2021, 8:27 PMSETY
12/04/2021, 8:27 PMsilentworks
12/04/2021, 11:14 PManothercoder
12/09/2021, 5:14 AMYANN
12/09/2021, 6:51 AMsql
create policy "Users can select personas is they have a relation (uuid)."
on persona
for select using (
auth.uid() = profile_id
);
create policy "Users can select personas if their profile status > 0"
on persona
for select using (
auth.uid() in (
select id from profile
where status > 0
)
);
anothercoder
12/09/2021, 7:35 AMYANN
12/09/2021, 7:43 AM