Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIKWa-0001uX-49 for pgsql-general@arkaria.postgresql.org; Thu, 01 Nov 2018 21:29:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gIKWY-0007N3-Eg for pgsql-general@arkaria.postgresql.org; Thu, 01 Nov 2018 21:29:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gIKWY-0007Mv-4T for pgsql-general@lists.postgresql.org; Thu, 01 Nov 2018 21:29:06 +0000 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gIKWV-0003iM-A7 for pgsql-general@postgresql.org; Thu, 01 Nov 2018 21:29:05 +0000 Received: by mail-pg1-x52d.google.com with SMTP id c10-v6so9623048pgq.4 for ; Thu, 01 Nov 2018 14:29:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version; bh=wA7AzCV8mpdOdhr4SisPl9MXjHKGq+Waqo3cI+u9pE8=; b=NbB9zqPNDN+sJm4wXRpehr1iKMKhzFYsMuIXAiqQEHybMPccwAZn9tzGGi1/c5XcRU zva9MC0MkV/RcG+NzR0sW49C8taaO7SFokzqDUQN+4q2L4jOTfTicIMX8u6rO+vGfVPP A5WBljl7tO55iH8sxGyy9u4H7/18aJkAxUj0Ly319QueF9SaqkaLCiLyMMzSOtjM22rs jutaRzX9+mVkncOZ254suoiOj26KqEwv5NWeSw35wrrK9AEP6qo73YR5uSPu1ZfZxjMK XVkQzJ2EHr7y8GRpSd9C4R76KLmRkhx75TmkftXH2sbKl0YYh89LkszIPptvtUcjmKcY GUVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version; bh=wA7AzCV8mpdOdhr4SisPl9MXjHKGq+Waqo3cI+u9pE8=; b=eigoSqdgar99igReWWfs4IxV3hvfz1hAyp7EzN/WqQX042O3Krm41f4evlbgxGt5R8 VrG/nrbvLe/0XjnfXhLUDePig10UguwyqTdosQvCVtmc+qrLkas+O0ZGZh/fqLMFgmEd AeRsLJjmZLY3g9V03bEqPukvtjP+vimZpVQgx+wgIewEWEoT1CJHLadzYjuAFzr8cJ8j U2b42iDYMcP+4pOxbLTziSVBDrn7UMSTp3ViXAC+nQ7ZFcZh0Nl07PQHEzTLjj9I3q8y jx1ZDBcwTZ9OdhW3mE2Z0bM063mq4EzwRD2XUw6p/KVPMNxnKnudAUgS5wXSkVuLJoRB b74w== X-Gm-Message-State: AGRZ1gIaYL9SdzZFPilfNNaBvBR0Ng/GOB5MH2AjuZ4mThOFrLDRsHkn ZgigRF1oK2+NFVH5Yk+8znNJ4O9a X-Google-Smtp-Source: AJdET5fRX1JuMyB53yCMxBmIHdgdmU6mgIOxUjAA80Xi9Ok+mUoG3sNXkYBQ8DNWKruFEC56qnGs/A== X-Received: by 2002:a63:2045:: with SMTP id r5-v6mr8549159pgm.328.1541107740363; Thu, 01 Nov 2018 14:29:00 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-64ce-c25f-72bb-315a.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:64ce:c25f:72bb:315a]) by smtp.gmail.com with ESMTPSA id s2-v6sm75376444pfk.133.2018.11.01.14.28.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 14:28:59 -0700 (PDT) References: User-agent: mu4e 0.9.18; emacs 26.1 From: Tim Cross To: Rich Shepard Cc: pgsql-general@postgresql.org Subject: Re: Add columns to table; insert values based on row In-reply-to: Date: Fri, 02 Nov 2018 08:28:56 +1100 Message-ID: <874ld0ij1j.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rich Shepard writes: > On Thu, 1 Nov 2018, Adrian Klaver wrote: > >>> alter table stations add column start_date date; >>> alter table stations add column end_date date; >>> alter table stations add column howmany integer; >>> alter table stations add column bin_col char(8); >>> >>> insert into stations (start_date, end_date, howmany, bin_col) values ( ) >>> select site_nbr from stations >>> where site_nbr = ' '; > >> Are you trying to add new data to existing records? > > Adrian, > > I am adding four columns to an existing table that already contains four > columns. > >> If so where is the new data coming from? > > I have a text file and will fill each insert statement by hand if there's > not a more efficient way to do this. > > Regards, > > Rich Like others, I'm not clear on exactly what your after here, but did want to point out 1. If your doing it by hand, you don't have to do a separate 'full' insert statement for every row i.e. insert into blah (x, y, z) values (....), (....), (....), .... (...); is valid syntax. You don't need to do a full "insert into blah (....) values (...)" for each insert. 2. If it really is an insert you want to do and you already have the data in a file e.g. CSV or similar, then you can use the \copy command to process the file, which is very fast. 3. Is it really insert or update you need? -- Tim Cross