kresimirgalic
07/12/2022, 5:53 PMproject_time_entries
with columns duration
in minutes, and table `project_members`where i have column `cost_rate`which is hourly rate of employee.
so what i want is to join those two tables, calculate all durations for this month and get income.
this is what i trie and it returns me duplicated rows
create or replace function get_time_entries_income (
start_date text, end_date text
)
returns table (
duration integer,
cost_rate integer
)
language plpgsql
as $$
begin
return query
select pt.duration, p.cost_rate
from project_time_entries pt
inner join project_members p
on pt.member_id = p.member_id
where work_date between start_date and end_date;
end
$$;
Steve
07/12/2022, 6:15 PMAlbert [tox/cis]
07/12/2022, 6:40 PMbackjisceglia
07/14/2022, 6:20 AMjaitaiwan
07/14/2022, 7:43 AMSTILLWATER;
07/16/2022, 4:22 PMWHERE U.id IN (SELECT ids from another table with some criteria)
Does this execute the SELECT id just once?
Is it better then join?
What about a query which matches id with some other value like
WHERE U.id = (SELECT id from another table with some criteria)
Does this run the SELECT id for every U.id in U for every row?garyaustin
07/16/2022, 4:50 PMSTILLWATER;
07/16/2022, 5:03 PMGünhan
07/17/2022, 3:23 PMCREATE OR REPLACE FUNCTION random_questions()
RETURNS int[] AS $$
SELECT array[id] FROM questions ORDER BY random() LIMIT 10;
$$
LANGUAGE SQL;
and this returns an array only one id, what i am doing wrong? any ideas?Günhan
07/17/2022, 3:25 PMGünhan
07/17/2022, 3:28 PMSELECT array_agg(id) FROM questions ORDER BY random() LIMIT 10;
did the trick, thanks!azel
07/18/2022, 3:47 AM[
{
"date": [
"2022-05-24",
"2022-05-26"
]
}
]
Here's the sample data that I have in my JSON column. It can have multiple datesedelacruz
07/18/2022, 5:40 AMedelacruz
07/18/2022, 5:41 AMedelacruz
07/18/2022, 5:51 AMgaryaustin
07/18/2022, 12:16 PMedelacruz
07/18/2022, 12:59 PMgaryaustin
07/18/2022, 1:01 PMedelacruz
07/18/2022, 1:02 PMedelacruz
07/18/2022, 1:05 PMimousart
07/19/2022, 6:01 PMgaryaustin
07/19/2022, 6:13 PMedelacruz
07/20/2022, 7:34 AMcreate or replace function test_function()
RETURNS text
LANGUAGE plpgsql
security definer set search_path = auth
as $$
declare user_role text;
begin
select raw_user_meta_data->>'role'
from auth.users
into user_role
where id = auth.uid()
return user_role;
end
$$;
When I call this function from within my js app it returns null
const {data, error} = await supabase.rpc('test_function')
When I replace auth.uid() with the id of an existing user it still returns null in my code
but when I run select * from test_function()
in Supabase Studio's SQL Editor I do get the role I assigned to my user
Why is there a difference between calling a function from code and calling it from the SQL Editor?
And why is auth.uid() not working?
To be clear; there is an authenticated user in the code that I'm calling from.Scott P
07/20/2022, 1:17 PMNin
07/20/2022, 4:46 PMSELECT t.day::timestamp
FROM generate_series(timestamp '2022-07-20 09:00:00.000000 +00:00'
, timestamp '2022-07-20 21:00:00.000000 +00:00'
, interval '1 hour') AS t(day);
NeoPrint3D
07/21/2022, 11:47 AMNeoPrint3D
07/21/2022, 11:48 AMkinau
07/21/2022, 12:23 PMkinau
07/21/2022, 12:24 PMNeoPrint3D
07/21/2022, 12:24 PM