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 1nrt9U-0004o1-Uq for pgsql-admin@arkaria.postgresql.org; Fri, 20 May 2022 03:18:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nrt9T-0000yG-JX for pgsql-admin@arkaria.postgresql.org; Fri, 20 May 2022 03:18:07 +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 1nrt9T-0000y7-61 for pgsql-admin@lists.postgresql.org; Fri, 20 May 2022 03:18:07 +0000 Received: from mail-oa1-x2c.google.com ([2001:4860:4864:20::2c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nrt9M-0006S2-OC for pgsql-admin@lists.postgresql.org; Fri, 20 May 2022 03:18:06 +0000 Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-e5e433d66dso8997521fac.5 for ; Thu, 19 May 2022 20:18:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to; bh=9Kih8j3UYIuagEPtQ6QcQW+0n8N0ekzc4iLpeuqLeM0=; b=IEng/F51MG+tjixS9fRtBFRMhW933StVQ/Es7uQk9SKHh4+Y3MouoU4si4Na6ZyXu+ CBWAgjEMJjMCEuwWRMuW/kzLoE88RRVJlMxAs+EzKP6x2ov2LZcASuNbTNaX/u9Ddbxw qZiil6XfTZkDMziTrzNVXrrgCePpMm1/4KNt6vsZDT3nyUgRCjcDdDrRrmERxv6k2PeD AJLZOVY+SuOEuFcRi+usRDB9E/ve/4UTzd1kMCKuEyJn5wZ2C6wBvjLLvlRJ06Q/cal7 iO0y/s6d5Ls0Cj7sGh06ziTAuc4cCqGLQSvo/yAPDvLT7dt+t9Xjy/qw/lVImf0cDqVy LtZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to; bh=9Kih8j3UYIuagEPtQ6QcQW+0n8N0ekzc4iLpeuqLeM0=; b=O8TVodsz5MD+koeGMOjiMEl0kwk/1xXJCZiFHUHWLx9CmEWMIX9rUGjdRAwyR6/hz/ titExDQeIqZC2V3ZUlgMPnNfEkkZHrOk+Xq6T1ZU93JOJ6JqK4DzgOY7Ncn15Iz2HZXV +pszquivWg5F2aw5DOagtwhRVF5L1K52X/2tOow/IdLPLD8geKzQVRZNyeJ7POtlyo0/ Wa6D0oars1FEwCEBg4gy3m/2rajjuXZlWwV9gORHXmUtosJQ4QYdXFoHHOizBcE7UF+n R5wAppo6cuchAfaGlDzkWEudwMmn/GoZvqCiA1cge6Zmf2cTuT+JAEb4DbRLmGuf5819 TS0w== X-Gm-Message-State: AOAM530b77rZB20evR0aJ4W/cFqRrx1+JX0MWbL6/TgMYoh4xoAzlL4s +XBgaHwdBKUmRbhiOJRzaH40VSU2IzU= X-Google-Smtp-Source: ABdhPJzz9LpI/fqiMnPXEUcJNk537hfXFoTDj2DdXtDm5XmN9gqoaWcBJJ6tz5zWVV8hzUeG75GSJA== X-Received: by 2002:a05:6870:f61a:b0:f1:7484:8eca with SMTP id ek26-20020a056870f61a00b000f174848ecamr4592930oab.107.1653016679700; Thu, 19 May 2022 20:17:59 -0700 (PDT) Received: from [192.168.88.10] (ip68-11-68-85.no.no.cox.net. [68.11.68.85]) by smtp.googlemail.com with ESMTPSA id r21-20020a056830237500b0060ae954bf27sm446425oth.62.2022.05.19.20.17.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 May 2022 20:17:59 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------Zc2o1wCvyPOOUSdhtSFoB3M3" Message-ID: Date: Thu, 19 May 2022 22:17:58 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: bash or sql script to copy foreign table to locale table Content-Language: en-US To: pgsql-admin@lists.postgresql.org References: From: Ron In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------Zc2o1wCvyPOOUSdhtSFoB3M3 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Please do not hijack existing threads. On 5/19/22 18:55, koff wrote: > Hi all, > > I need little help  please, > > I'v  already   foreign tables (from oracle_fdw) in my  postgresql > environment. > > I'm Just  looking for  script shell  or sql  ( easy way)  to migrate  > this  foreign tables   to locale  table . > > My script below  has some issue > > thanks lot > > ------script migrate--- > > #!/bin/bash > export PGDATA=/pg01/pgdata/9.6/data > export PGUSER="postgres" > export PGPORT="5433" > export PGPASSWORD="ttooe2" > > for tbl in `psql -qAt   data_2020 -c "select  foreign_table_name  from > information_schema.foreign_tables;"`; > do                   ## note the added semicolon >     psql data_2020  -c "create table public.\"$tbl\" as select * from > fdw_link.\"$tbl\";" Here, either psql COPY the fdw_link.\"$tbl\" data OUT to a local file, and then COPY IN to public.\"$tbl\" *OR* INSERT INTO public.\"$tbl\" SELECT * FROM fdw_link.\"$tbl\"; > done > > ----end  of script--- > > the database is :  data_2020 > >  foreign_table schema   is :  fdw_link > > and want to copy  to public  schema > > > > > > -- Angular momentum makes the world go 'round. --------------Zc2o1wCvyPOOUSdhtSFoB3M3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Please do not hijack existing threads.

On 5/19/22 18:55, koff wrote:
Hi all,

I need little help  please,

I'v  already   foreign tables (from oracle_fdw) in my  postgresql environment.

I'm Just  looking for  script shell  or sql  ( easy way)  to migrate  this  foreign tables   to locale  table .

My script below  has some issue

thanks lot

------script migrate---

#!/bin/bash
export PGDATA=/pg01/pgdata/9.6/data
export PGUSER="postgres"
export PGPORT="5433"
export PGPASSWORD="ttooe2"

for tbl in `psql -qAt   data_2020 -c "select  foreign_table_name  from information_schema.foreign_tables;"`;
do

                  ## note the added semicolon
    psql data_2020  -c "create table public.\"$tbl\" as select * from fdw_link.\"$tbl\";"
Here, either psql COPY the fdw_link.\"$tbl\" data OUT to a local file, and then COPY IN to public.\"$tbl\" OR INSERT INTO public.\"$tbl\" SELECT * FROM fdw_link.\"$tbl\";

done

----end  of script---

the database is :  data_2020

 foreign_table schema   is :  fdw_link

and want to copy  to public  schema







--
Angular momentum makes the world go 'round.
--------------Zc2o1wCvyPOOUSdhtSFoB3M3--