Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLBlH-0002cy-QR for pgsql-general@arkaria.postgresql.org; Mon, 29 Apr 2019 19:16:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hLBlG-00079r-5t for pgsql-general@arkaria.postgresql.org; Mon, 29 Apr 2019 19:16:22 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLBlE-00075m-Sz for pgsql-general@lists.postgresql.org; Mon, 29 Apr 2019 19:16:21 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hLBlB-0001P0-L5 for pgsql-general@lists.postgresql.org; Mon, 29 Apr 2019 19:16:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 63AA622006; Mon, 29 Apr 2019 15:16:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Mon, 29 Apr 2019 15:16:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=a 8g3uENV4Fq9ggveTO+m7teqpXQ8X2U41TYi+dKUsj8=; b=nX8W2YZk/qF6brHfL VnbB7OoZtTXRK6pjV8kvlaxD6uvBJX9PhuN3CM9F9zjBOGf3jgjAN/tqvP6SRh53 JMueFED0T4V82WaXTGMxxUkQ1l7wHrfh/6vdyt2ShdaifJDDOXi9f6HlwKMZk8Ls OTsja1f+L2bxjjukh2GJo01e3W3qrVuOumDDnl+YjrPRKOfnJ4XLSh2dn02xCKYb iFMKqhELsRrSNw60zs8VmJDGVStAz5KZ3xwqvdrIrWwt/uX6oiQJLhd+o76blX/4 uM2DGnxUpMubiboY9nlFHztV3gC2yd1MqzCLapt1R+tqWfAcboWYQ9XsMoEYr1lF 7DUVA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=a8g3uENV4Fq9ggveTO+m7teqpXQ8X2U41TYi+dKUs j8=; b=zkJin8rNAG+/n1W0Wn8t/bwwK5ZILsGFQmLsWvYXr/y987UGsLCCE5E2G JxXy81SdfxlZy9e4oRmNQ7CyjJA13fC34rTh5Lh3tIxUG9Ie9U4FCR3+DIP6WlEF gR0WPcY34xMPapsvR0aO35wHebC2q3XtyxEQIJDXQZomIrZLS/eF+HmHnwd+sg3V sU+QptkNVrGGVViJqrPfPC2GriCwKxc+FbpebSCKPZOdYR/iZzmPDSiXggqLiBkm ZUSzmdEV/FchJ3tV/2qnQei0ZjSEWchvx3ZYOZT7oYQNDj2YsQnrLWBLbIWauWlx pDd7SOk0/xu/2pjCcx/3YMo7bqHsA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddriedvgddufeejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefheenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgnecukfhppeejuddrvddu vddrudehtddrvddtvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklh grvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id E7636103CC; Mon, 29 Apr 2019 15:16:14 -0400 (EDT) Subject: Re: How to execute .sql file inside a postgres schema To: Daulat Ram , "pgsql-general@lists.postgresql.org" References: From: Adrian Klaver Message-ID: <3f1fa598-7d03-0577-fb6a-a6dde52f81de@aklaver.com> Date: Mon, 29 Apr 2019 12:16:13 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/29/19 7:02 AM, Daulat Ram wrote: > Hello team, > > I have a database name “kbdb” that is having a schema “kb” and I want to > execute the test.sql file inside this schema, > > Please help how we can do that. You can do as Daniel suggested but be aware that it is equivalent to: https://www.postgresql.org/docs/11/sql-set.html SET search_path TO value That means if you have objects in the script that are not schema qualified and need to point to other schemas then things will fail. A longer term solution would to schema qualify the objects in your script. This is assuming that the script is not generic and is meant to 'float' from schema to schema. > > Regards, > > Daulat > -- Adrian Klaver adrian.klaver@aklaver.com