Create constraint for stopping mass update to a table I want to create a constraint so that if more than 5 rows in a table are getting updated with an UPDATE statement it should warn the user / block the query.
One way to implement this would be with a trigger updating a temporary table in parallel (that is only visible inside the same session).  

Create the temp table with ON COMMIT DROP, so that it lives for the duration of a transaction. This way, all updates during the same transaction count against the maximum.

Demo table:

CREATE TABLE foo(id serial, txt text)


Trigger function:

CREATE OR REPLACE FUNCTION trg_foo_maxup()
  RETURNS trigger AS
$func$
DECLARE
  _ct int;
BEGIN

IF EXISTS (
   SELECT 1 FROM pg_catalog.pg_class
   WHERE  relname = 'foo_maxup'
   AND    relnamespace = pg_my_temp_schema()
   AND    relkind = 'r'
   ) THEN

   UPDATE foo_maxup SET ct = ct + 1
   RETURNING ct INTO _ct;

   IF _ct &gt; 5 THEN           -- your maximum here
      RAISE EXCEPTION 'Cannot update more than 5 rows in one transaction!';
   END IF;

ELSE
   CREATE TEMP TABLE foo_maxup ON COMMIT DROP AS
   SELECT 1 AS ct;
END IF;

RETURN NEW;

END
$func$
  LANGUAGE plpgsql VOLATILE SET search_path = pg_temp;


Trigger:

CREATE TRIGGER maxup
BEFORE UPDATE ON foo
FOR EACH ROW
EXECUTE PROCEDURE trg_foo_maxup();


If you want a maximum for the whole session, just omit ON COMMIT DROP.

I added SET search_path = pg_temp to the function definition to prevent mischief with the search_path. This trigger only sees temporary tables in its search_path. That's why pg_catalog.pg_class has to be table-qualified.

-> SQLfiddle demo.