Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mac2u-0003g0-0o for pgsql-general@arkaria.postgresql.org; Wed, 13 Oct 2021 11:03:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mac2t-0006Vy-1K for pgsql-general@arkaria.postgresql.org; Wed, 13 Oct 2021 11:03:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mabzi-0006iG-Hf for pgsql-general@lists.postgresql.org; Wed, 13 Oct 2021 11:00:22 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mabzf-0007dV-G3 for pgsql-general@lists.postgresql.org; Wed, 13 Oct 2021 11:00:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/A+IsI+1jLwtQqHcri5TlzncXF95UjU7JCo/pThMcTo=; b=FZaEbS6uqOv2urxgMJFLOFP/cL Nk70iRqbFBZP1Y02/ZfAMVLeaGAJTddyxMvT67eGcL3x79g3mk21RqSgtgEf6JAgsEDJaGDlB1vNO 8Nvthpoe/y5yl1IJpkLKRpN97XL2qLoXnOEysCUmYL6US8oNKVMUgGdvTKH8p0qUU29Q=; Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by depesz.com with esmtpa (Exim 4.92) (envelope-from ) id 1mabzc-0004he-5H; Wed, 13 Oct 2021 13:00:16 +0200 Date: Wed, 13 Oct 2021 13:00:16 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Vijaykumar Jain Cc: celati Laurent , pgsql-general Subject: Re: Grant select for all tables of the 12 schemas of my one db ? Message-ID: <20211013110015.GA11950@depesz.com> Reply-To: depesz@depesz.com References: <20211013095214.GA17654@depesz.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Oct 13, 2021 at 03:33:20PM +0530, Vijaykumar Jain wrote: > something like this ? Like, but not exactly. Consider what will happen if you have schema named "whatever something else" - with spaces in it. Or "badlyNamedSchema". Generally you'd want to use: execute format('GRANT USAGE ON SCHEMA %I TO readonlyuser_role', sch); and it will take care of it. > also, > in case you like, I have kind of liked this > you can try running meta commands using psql -E to get the query that you > would like to run for DO block. while in psql, you can simply: select format() ... from ...; make sure that it returns list of correct sql queries, with no mistakes, and with ; at the end of each command, and then rerun it like: select format() ... from ... \gexec depesz