Column Presets as SQL queries/References to Column Values #6540
Unanswered
browniefed
asked this question in
General
Replies: 1 comment 1 reply
-
As a workaround you can create a pre-insert trigger and use the Tables
Create a Function that will run before the insert getting the session variables and the name from the other table based on the user-id CREATE OR REPLACE FUNCTION public.user_preset()
RETURNS TRIGGER
LANGUAGE PLPGSQL
AS
$$
DECLARE
session_variables json;
user_name text;
user_id bigint;
BEGIN
session_variables := current_setting('hasura.user', 't');
user_id := session_variables ->> 'x-hasura-user-id';
SELECT name into user_name FROM public.username where id = user_id;
NEW.user_id_from_session = user_id;
NEW.session_variables = session_variables;
NEW.user_name_from_table = user_name
RETURN NEW;
END;
$$ Create a trigger to run before the insert and call the function CREATE TRIGGER set_user_preset
BEFORE INSERT
ON public.user
FOR EACH ROW
EXECUTE PROCEDURE public.user_preset(); |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
It would be great if a column preset could leverage the Hasura claims to then query for another value in the database to insert as the value rather than utilizing the Hasura Claim value only.
Beta Was this translation helpful? Give feedback.
All reactions