How to use WITH inside IF statement in PostgreSQL
IF does not exist in the SQL language (which is why you get a syntax error) but it's available in plpgsql, the procedural language.
With plpgsql, you could write something like
CREATE OR REPLACE FUNCTION public.get_something(myTextFlag VARCHAR(20)) RETURNS TABLE 
(
rNum BIGINT,
Colmn1 Text
)
AS $body$
BEGIN
IF (myTextFlag = 'FirstPart') THEN
  RETURN QUERY &lt;insert your 1st query here&gt;
ELSE
  RETURN QUERY &lt;insert your 2nd query here&gt;
END IF;
END
$body$
LANGUAGE plpgsql
SECURITY DEFINER
 STABLE;

Your 1st and 2nd queries must return the same structure that also must match the function definition, but aside from that, they can be completely different inside.