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 1i16cN-0005TU-HO for pgsql-general@arkaria.postgresql.org; Fri, 23 Aug 2019 10:16:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1i16cL-0000uf-JT for pgsql-general@arkaria.postgresql.org; Fri, 23 Aug 2019 10:16:25 +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 1i16cK-0000uY-So for pgsql-general@lists.postgresql.org; Fri, 23 Aug 2019 10:16:25 +0000 Received: from mail.wordtothewise.com ([104.225.223.158]) by makus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1i16cI-0006lg-4m for pgsql-general@lists.postgresql.org; Fri, 23 Aug 2019 10:16:23 +0000 Received: from [10.214.156.206] (unknown [217.173.105.122]) by mail.wordtothewise.com (Postfix) with ESMTPSA id 086B19F147 for ; Fri, 23 Aug 2019 03:16:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wordtothewise.com; s=aardvark; t=1566555381; bh=TFuyU24els/FQQo+2yOPOGFNDqodaWWQMWF21Xxr8sA=; h=Subject:To:References:From:Date:In-Reply-To:From; b=MawxgqYBhf0VPgzjQj9vCUUxshkA4sr5UjE3z1n4rJesM/khFfuBa0/2FzY1qhKN8 4G4J3UEICArtBMaAhGbGKl/YfpyjFctOG/PENJty5Gseso/P7TydEfsp2zUkwstroX 4KbwIlmdvTnco2eaAQIU8/b8c/VkZb/DxKGLi3Dg= Subject: Re: Importing from CSV, auto creating table? To: pgsql-general@lists.postgresql.org References: <20190821211530.GA1292@panix.com> From: Steve Atkins Message-ID: <55fecc3f-813d-9414-8875-d63044a878bf@blighty.com> Date: Fri, 23 Aug 2019 11:16:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190821211530.GA1292@panix.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 21/08/2019 22:15, stan wrote: > I have a situation where we need to import data, as an interim measure, > from spreadsheets. > > I have read up on \copy and COPY, but I do not see that either of these can > use the header from a CSV file to define a new table. Am I missing > something? > > Also downloaded something called pgfutter, which I thought would do this, > but have not had any success with this. After I (thought) I had figured out > the arguments, it just seams to hag forever. > You might find https://github.com/wttw/csvpg useful. It creates tables with column names based on the CSV header, and data types intuited from the data. (The only pre-built binary there is for Mac right now; I should at least add one for Windows). Cheers,   Steve