0

This answer is great for when I needed to reown 150 tables, each with 40 tables, but displays the 6000 rows from SELECT before running the 6000 ALTER statements.

Thus, as stated in the Subject, is there any way to suppress the SELECT output?

sides=> SELECT format(
sides(>   'ALTER TABLE %I.%I.%I OWNER TO sides_owner;',
sides(>   table_catalog,
sides(>   table_schema,
sides(>   table_name
sides(> )
sides-> FROM information_schema.tables
sides-> WHERE table_schema = 'strans';
                                       format                                        
---------------------------------------------------------------------
 ALTER TABLE sides.strans.foo OWNER TO sides_owner;
 ALTER TABLE sides.strans.blarg_p2020_02 OWNER TO sides_owner;
 ALTER TABLE sides.strans.blarg_p2020_03 OWNER TO sides_owner;
 ALTER TABLE sides.strans.blarg_p2020_04 OWNER TO sides_owner;
 ALTER TABLE sides.strans.blarg_error_p2019_01 OWNER TO sides_owner;
 etc
 etc
 etc
2

Thus, as stated in the Subject, is there any way to suppress the SELECT output?

Yes, by omitting the semi-colon after the SQL statement. That is, \gexec itself ends the SQL statement.

test=> select 'select 1' \gexec
 ?column? 
----------
        1
(1 row)
2
  • Why does ; change the behavior? – RonJohn Feb 24 at 6:09
  • 1
    @RonJohn: strictly speaking ; is not part of the query. It's meant to say "send the query that is before that semicolon". It's almost a command (except when there are multiple queries per line, then it's both a separator and a command) – Daniel Vérité Feb 24 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.