burggraf
08/07/2021, 11:35 PMSubh
08/08/2021, 3:02 PMsyntax error at or near "::". null
CREATE
OR REPLACE FUNCTION public.group_by_temp(col_name text DEFAULT 'country' :: text, project_id uuid :: uuid, date_range text :: text) RETURNS SETOF group_by_col_dummy LANGUAGE plpgsql STABLE AS $ function $ BEGIN RETURN QUERY EXECUTE format(
'select %I as col, count(*) from session where project_id = %s, %s::daterange @> created_at group by %I',
col_name,
project_id,
date_range
col_name,
);
END $ function $
Scott P
08/08/2021, 6:16 PMcol_name text DEFAULT 'country' :: text, project_id uuid :: uuid, date_range text :: text
should be
col_name text DEFAULT 'country', project_id uuid, date_range text
::
is used for coercing a value to a specific type and shouldn't be used for function args.
For example, if you had a really long number (e.g. 20210808123456789012345678901234567890), you could use :: TEXT
to force it to be text
type instead of int
type. Use cases could include working with JS, where you want to display the full value but the language itself might not be able to understand that it's a number.Subh
08/08/2021, 6:18 PMCREATE OR REPLACE FUNCTION public.group_by_col3(_colname text, _projectid text, _daterange text)
RETURNS SETOF group_by_col_dummy
LANGUAGE plpgsql
STABLE
AS $function$
BEGIN
RETURN QUERY EXECUTE format('select %I as col, count(*) from session where project_id = ''%s'' AND tstzrange(''%s'') @> created_at group by %I', _colname, _projectid, _daterange, _colname);
END
$function$
I ended up writing this.Subh
08/08/2021, 6:19 PMIlko Kacharov
08/09/2021, 8:56 PMdailylurker
08/11/2021, 8:47 AMburggraf
08/11/2021, 12:26 PMdailylurker
08/12/2021, 12:25 PMcopple
08/12/2021, 2:14 PMselect
policy - see the note here: https://supabase.io/docs/reference/javascript/insert#notesburggraf
08/12/2021, 2:28 PMLeDragunov
08/12/2021, 5:34 PMMihai Andrei
08/12/2021, 5:39 PMMihai Andrei
08/12/2021, 5:39 PMLeDragunov
08/12/2021, 5:44 PMLeDragunov
08/12/2021, 5:45 PMScott P
08/12/2021, 5:48 PMMike92988
08/12/2021, 8:53 PMburggraf
08/12/2021, 11:59 PMuser
08/13/2021, 2:24 PMflorian-lefebvre
08/13/2021, 3:33 PMflorian-lefebvre
08/13/2021, 3:33 PMlawrencecchen
08/14/2021, 7:34 AMuser
08/14/2021, 9:15 AMuser
08/14/2021, 9:17 AMuser
08/14/2021, 9:17 AMcreate type public.user_status as enum ('ONLINE', 'OFFLINE');
create type public.message_type as enum ('TEXT', 'IMAGE', 'VIDEO');
create table channels (
id uuid default uuid_generate_v4() primary key
);
create table messages (
id uuid default uuid_generate_v4() primary key,
content text not null,
type public.message_type not null,
channelId uuid references channels (id),
sentAt timestamp default now() not null
);
create table users (
id uuid default uuid_generate_v4() primary key,
name text not null,
phoneNumber text not null,
status public.user_status not null,
image text not null,
bio text
);
create table members (
id uuid default uuid_generate_v4() primary key,
userId uuid references users (id),
channelId uuid references channels (id)
);
user
08/14/2021, 9:18 AMmany-to-many
relationships, I've made a members
table to join them togetherMihai Andrei
08/14/2021, 9:57 AMflorian-lefebvre
08/14/2021, 10:21 AMtext
[id: 3, title: Category3, parentId: 2],
[id: 2, title: Category2, parentId: 1],
[id: 1, title: Category1, parentId: null]
I found that postgres has recursive views so I found a tutorial and I have:
sql
drop view if exists category_path;
create recursive view category_path (id, path) as
select
id,
title as path
from
categories
where
"parentId" is null
union all
select
c.id,
(cp.path || ' > ' || c.title) as path
from
categories c
join category_path cp on c."parentId" = cp.id;
Doing select * from category_path where id = 3;
returns [id:3, path:Development > Back-end]
.
Here is my categories
table:florian-lefebvre
08/14/2021, 1:12 PMsql
drop table if exists resources;
drop table if exists categories;
create table categories (
id bigint generated by default as identity,
title varchar not null,
parent_id bigint references categories (id),
primary key (id),
unique (title)
);
drop function if exists public.category_hierarchy;
create function public.category_hierarchy(id_param int)
returns table (
id bigint,
title varchar,
parent_id bigint
)
as $$
begin
return query with recursive parents
as (
select
c1.id,
c1.title,
c1.parent_id
from categories c1
where c1.id = id_param
union
select
c2.id,
c2.title,
c2.parent_id
from categories c2
inner join parents p on p.parent_id = c2.id
) select * from parents;
end;
$$ language plpgsql security definer;
and then
sql
select * from category_hierarchy(5);
returns