      AND Part.parent IS NOT NULL
      AND Part.version IS NULL
      AND Part.serial IS NULL
+     LIMIT 1
    );
    IF parent_id IS NULL THEN
     -- Try same part without version or parent (root part)

  AND agentString = inAgentString
  AND fromAddress = inIPAddress
  AND ((referring = referringURL) OR (referring IS NULL AND referringURL IS NULL))
 );

 IF existingSession IS NULL THEN

  WHERE country = countrycode_id
   AND area = inAreaCode
   AND number = inNumber
  LIMIT 1
 );
END;
$$ LANGUAGE plpgsql;
