I'm new to pg and dbs in general. I found a blog db boilerplate and I'm trying to add some computed columns to return Booleans for whether the currentPerson (the authenticated user) is the author of a post. Basically, a phantom column in the posts table that has a true or false for each post as to whether the currentPerson authored it.
This function returns the currentPerson:
SELECT *
FROM myschema.person
WHERE id = nullif(current_setting('jwt.claims.person_id', true), '')::uuid
So, I would like to do something like below, but this is not correct. This appears as a mutation in graphiql (I'm using postgraphile to generate my schema).
Any tips on how to create an isMyPost
boolean computed column in a posts table would be awesome.
CREATE OR REPLACE FUNCTION myschema.is_my_post(
)
RETURNS BOOLEAN AS
$func$
BEGIN
SELECT *
FROM myschema.post
WHERE author_id = nullif(current_setting('jwt.claims.person_id', true), '')::uuid;
IF FOUND THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END
$func$ LANGUAGE plpgsql;