I have the following (working) code that I run from the command line:
DO $$
DECLARE first_ext INTEGER;
        last_ext INTEGER;
BEGIN
   first_ext:=100;
   last_ext:=150;
   INSERT INTO widgets (username)
   SELECT i
   FROM generate_series(first_ext, last_ext) AS t(i);
   INSERT INTO widget2
   SELECT generate_series(first_ext, last_ext), 'sometext', 
          generate_series(first_ext, last_ext);
END $$;
I'd like to now do a count on the two tables to make sure that i have correctly created data.
But I'm having a hard time returning the value. This is what I tried: 
RETURNS rec_count AS
DO $$
DECLARE first_ext INTEGER;
        last_ext INTEGER;
BEGIN
   first_ext:=100;
   last_ext:=150;
   INSERT INTO widgets (username)
   SELECT i
   FROM generate_series(first_ext, last_ext) AS t(i);
   INSERT INTO widget2
   SELECT generate_series(first_ext, last_ext), 'sometext', 
          generate_series(first_ext, last_ext);
   SELECT COUNT(*) FROM widget2 INTO rec_count;
END $$;
But it fails with the following error:
ERROR: syntax error at or near "RETURNS" LINE 1: RETURNS rec_count AS
I don't want to make this into a function / stored proc.
Is there any other way to do this? 
 
     
    