I need help with a query in postgress , i am trying to check if a column has a value or not and to do an insert
I have two databases on local and on is in server and in this table ccpt_data.user_role_permission in column user_role_name I have permission :
Locally I have this query and works :
INSERT INTO ccpt_data.user_role_permission(user_role_name, permission_name)
VALUES ('manager','MANAGE_SENSITIVE_DATA');
For the server will be something
INSERT INTO ccpt_data.user_role_permission(user_role_name, permission_name)
VALUES ('ROLE_PROJECT_MANAGER','MANAGE_SENSITIVE_DATA');
But I can't do it like this so I need if-else condition, to check for example if at ccpt_data.user_role_permission in user_role_name has a manager than I will do this and else the other this, so i am trying on something but as I don't know Postgres I need some help. I am trying :
DO
$do$
BEGIN
IF EXISTS (SELECT FROM ccpt_data.user_role_permission Where user_role_name = manager ) THEN
INSERT INTO ccpt_data.user_role_permission(user_role_name, permission_name)
VALUES ('ROLE_PROJECT_MANAGER','MANAGE_SENSITIVE_DATA');
ELSE
INSERT INTO ccpt_data.user_role_permission(user_role_name, permission_name)
VALUES ('manager','MANAGE_SENSITIVE_DATA');
END IF;
END
$do$