#pgsql trigger jsonb issue
16 messages · Page 1 of 1 (latest)
CREATE OR REPLACE FUNCTION notify_on_friend_request() RETURNS TRIGGER AS $$
DECLARE
notification_payload JSONB;
BEGIN
notification_payload = jsonb_build_object(
'request_id', NEW.id,
'from_user', (
SELECT jsonb_build_object(
'id', u.id,
'username', u.username
)
FROM "user" u
WHERE u.id = NEW.from_user
),
'to_user', (
SELECT jsonb_build_object(
'id', u.id,
'username', u.username
)
FROM "user" u
WHERE u.id = NEW.to_user
),
'status', NEW.status, -- Include the 'status' column
'updated_at', NEW.updated_at
);
PERFORM pg_notify('friend_requests', notification_payload::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
anyone know if those selects are correct?
where are you running this query?
This is function that is being triggered by trigger that runs on each insert to friend_requests table
this is my migration file,here you can see im creating trigger for table friend_requests calling this trigger that long name,and function in this case is what trigger calles upon INSERT into said table
honestly it worked before but when i reverted to the old code it no longer works
issue is that NEW which should be returning said inserted row is returning null and since this is something i do in free time,im kinda stuck on this for 2 days already ofc with my limited time for personal programming
wish i knew the problem, but SQL isn't something I'm too familiar with either
Unfortunately this isn't an issue with Railway. This server is for Railway help, not code help.
I'm not going to ping anyone in to help, you'll have to wait for someone to stumble on this thread with the answer or visit another server that provides code help