Fastest way to check if record is related to a particular user in postgres
You can use PERFORM 1 test with a control statement using FOUND special variable. Your query will get like this;

PERFORM 1 
    FROM ks.shares 
    WHERE
        id = Pshareid AND userid = Puserid
    LIMIT 1;

IF FOUND THEN
  -- Cannot like your own share
ELSE
    --INSERT the new record
END IF;


Referenced sections;

Executing a Command With No Result

Available Diagnostics Items (special variable named FOUND)