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 1oIx2Z-0005xp-9J for pgsql-general@arkaria.postgresql.org; Tue, 02 Aug 2022 18:54:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oIx2Y-0002Oq-4g for pgsql-general@arkaria.postgresql.org; Tue, 02 Aug 2022 18:54:50 +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 1oIx2X-0002Oh-OT for pgsql-general@lists.postgresql.org; Tue, 02 Aug 2022 18:54:49 +0000 Received: from mail-ot1-x332.google.com ([2607:f8b0:4864:20::332]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oIx2V-0000HC-IH for pgsql-general@lists.postgresql.org; Tue, 02 Aug 2022 18:54:48 +0000 Received: by mail-ot1-x332.google.com with SMTP id br15-20020a056830390f00b0061c9d73b8bdso10812063otb.6 for ; Tue, 02 Aug 2022 11:54:47 -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:content-transfer-encoding; bh=gSb7rQl5O1aC9ozCmAgb41uG/ukFdj9CZc7zLst1QMI=; b=kBBdfqjcTah8YavIPmjcltlA+PGjQAUCFMf27ZkQ/c9tGt4t3QFKHzLo1/4vER2S9B 4xX/yIiyrBt40A7IoWvRBkcY3miYy704gsnPne3iUCLeLOm+n+bi1AtJd8yR3bXRX700 DPJ5KL5E++1tHqhTD/aCl3NePDt5O0PhN90xpkviyLOxojZF+ENCuavDpqT3ELdzc9yv GSNMK7A1ODhZGzc79DSt4qFyh1VkW21lVtrJ7ABiy2fNkpY15M0PSojpDRAC9Bex8a2k SDnIE2Si/gc+IFt1LxwIkNHx3NfPsrlIGki+JlAmDaadxZtr6l72KHZg7ggK7dkYvjG2 1SGg== 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 :content-transfer-encoding; bh=gSb7rQl5O1aC9ozCmAgb41uG/ukFdj9CZc7zLst1QMI=; b=1ifGZ/Iu+jsW34bVzwDZv2YaTpinmbHl6BIi3DsQQ60lS2BwEQPkvUlQ8D3mtkpfzN WRbiUF8fPAUCJW4vlCrMX5nJ7Q7iavIqsw3jCcqQsCWlVRK+rsEapozDqb9f7kyH6qEu G4ITvrvhf9J2DBDnb6TGNCCWRjA6g3MQoTYSi7bAoH2/BIdhrUKTMDw9eix7Hk9I+3dh HAN4Grr4TqZI7dRp+eLyJ6SQjFVCFWho/yJw666cljGdLFGBPySdJGB4PySXAQciFwVh 0XmJbcsZemKA+Dh7+roTX+AgvXYmd+r+eyBZYDzSBQ6xro6Ue7ECPCRDp0QuJpmzroSP jbYg== X-Gm-Message-State: AJIora/WIfsrasM0U4S1qMX9hIVfvfOKklYqzaK7a+8KVyb/8K3t4eMQ 3DwbYKvn5rZXum6kAz/BPLtgQAoY1Ts= X-Google-Smtp-Source: AGRyM1unZ1ZJW4/jB/0e1Nfj3IeziE8KkOFL7VhFilfJZzB8+U8M3fWYscoVMynclxfwrdl3flyjwg== X-Received: by 2002:a05:6830:248c:b0:61c:98a2:105d with SMTP id u12-20020a056830248c00b0061c98a2105dmr8149521ots.158.1659466486634; Tue, 02 Aug 2022 11:54:46 -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 j2-20020a4adf42000000b0042313f42b26sm3460847oou.39.2022.08.02.11.54.45 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 02 Aug 2022 11:54:46 -0700 (PDT) Message-ID: <195a23f4-f640-3af2-207a-426888eefdb0@gmail.com> Date: Tue, 2 Aug 2022 13:54:45 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: Copying records from TABLE_A to TABLE_B (in the same database) Content-Language: en-US To: pgsql-general list References: <5adcc923-889d-bb68-5a04-60125b6f0e96@gmail.com> <5c9cf0c3-e530-fb39-1409-096b343b2c75@aklaver.com> From: Ron In-Reply-To: <5c9cf0c3-e530-fb39-1409-096b343b2c75@aklaver.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/2/22 13:41, Adrian Klaver wrote: > On 8/2/22 11:37 AM, Ron wrote: >> AWS RDS Postgresql 12.10 >> >> There are no indices or constraints (except for NOT NULL) on table_a. >> >> The two ways that I know are: >>      INSERT INTO table_a SELECT * FROM table_b; Argh, I got the tables backwards.  Should be: INSERT INTO table_b SELECT * FROM table_a; >> and >>      \COPY table_a TO '/tmp/table_a.tsv' WITH (FORMAT BINARY); >>      \COPY table_b FROM '/tmp/table_a.tsv' WITH (FORMAT BINARY); >> >> Is there a faster/better way? >> > Does table_a have existing records? Yes.  Just before the copy, table_b was created using:     CREATE TABLE table_b (LIKE table_a INCLUDING CONSTRAINTS INCLUDING DEFAULTS); The only constraints on table_a are NOT NULL on various fields. > If so do you care if there are duplicates? TABLE_A (the source) has a UNIQUE index.  I'll be adding a similar PK on TABLE_B after the copy. > How large a data set are you talking about? It's varied.  The biggest have up to 20M rows with a bytea field, and others with 50M rather large (but no bytea) fields. INSERT INTO is good enough for the small tables. -- Angular momentum makes the world go 'round.