chipilov
11/16/2021, 9:40 AMchipilov
11/16/2021, 9:40 AMchipilov
11/16/2021, 9:40 AMstibbs
11/16/2021, 9:48 AMchipilov
11/16/2021, 12:53 PMcoozamano
11/17/2021, 3:55 AMDeleted User
11/17/2021, 9:44 AMSELECT
s.*,
p
FROM service s
CROSS JOIN LATERAL json_array_elements(pets) p
WHERE p->>'type' == 'dog'
returns an error:
function json_array_elements(json[]) does not exist
Any idea?
The column is a json[] datatype and the data instead is
[
{
"type": "cat",
"price": 10
},
{
"type": "dog",
"price": 20
}
]
I've read the official documentation about JSON data https://supabase.io/docs/guides/database/json - but there is no mention of an array of objects.tourdownunder
11/18/2021, 6:24 PMM0nk3yBrainDead
11/19/2021, 6:28 AMhaydn
11/19/2021, 6:56 AMperson_id
foreign key column on both your teacher
and student
tables. You can then enforce a 1:1 relationship between student
and person
by having a unique constraint on the person_id
column in the student
table. However, depending on what you're trying to do, you might no even need a person table. Something like select id, name from student union all select id, name from teacher
will give you all the "people".erik_flywheel
11/19/2021, 7:27 PMerik_flywheel
11/19/2021, 8:04 PMApfelsaft
11/21/2021, 9:14 PMtourdownunder
11/21/2021, 10:00 PMchipilov
11/22/2021, 2:15 PMchipilov
11/22/2021, 5:07 PMjon.m
11/24/2021, 2:24 AMcreate or replace function fetch_slim_profile (
userid uuid
)
returns table (return_id bigint, return_avatar varchar, return_fullname varchar, return_app_received boolean, return_app_accepted boolean, return_conversation_started boolean, return_search_tracking boolean)
language plpgsql
as $$
begin
return query select profiles.id, avatar, fullname, app_received, app_accepted, conversation_started, search_tracking from profiles inner join
user_settings on profiles.user_id = user_settings.user_id where profiles.user_id = userid;
end; $$
garyaustin
11/24/2021, 2:39 AMjon.m
11/24/2021, 2:44 AMjon.m
11/24/2021, 2:44 AMjon.m
11/24/2021, 2:52 AMjon.m
11/24/2021, 2:52 AMgaryaustin
11/24/2021, 2:53 AMjon.m
11/24/2021, 3:00 AMchipilov
11/24/2021, 1:24 PMchipilov
11/24/2021, 3:03 PMzakaria.chahboun
11/27/2021, 5:01 PMzakaria.chahboun
11/27/2021, 5:04 PMSQL
create or replace function change_user_password(current_plain_password varchar, new_plain_password varchar)
returns json
language plpgsql
security definer
SET search_path = extensions
as $$
DECLARE
_uid uuid;
BEGIN
-- First of all check the new password rules
-- not empty
IF (new_plain_password = '') IS NOT FALSE THEN
RAISE EXCEPTION 'change_user_password refuse'
USING DETAIL = 'new password is empty';
-- minimum 6 chars
ELSIF char_length(new_plain_password) < 6 THEN
RAISE EXCEPTION 'change_user_password refuse'
USING DETAIL = 'it must be at least 6 characters in length';
END IF;
-- Get user by his current auth.uid and current password
SELECT id INTO _uid
FROM auth.users
WHERE id = auth.uid()
AND encrypted_password =
crypt(current_plain_password::text, auth.users.encrypted_password);
-- Check the currect password
IF NOT FOUND THEN
RAISE EXCEPTION 'change_user_password refuse'
USING DETAIL = 'incorrect password';
END IF;
-- Then set the new password
UPDATE auth.users SET
encrypted_password =
crypt(new_plain_password, gen_salt('bf'))
WHERE id = auth.uid();
RETURN '{"data":true}';
END;
$$
the code is works fine in Supabase SQL editor, but when i call it as an RPC i got this error message
{ "hint": null, "message": "invalid salt", "code": "22023", "details": null}
Khan W
11/28/2021, 3:45 AMKhan W
11/28/2021, 3:45 AM