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 1gqgy8-0002mQ-T3 for pgsql-sql@arkaria.postgresql.org; Mon, 04 Feb 2019 16:19:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gqgy7-00014g-9X for pgsql-sql@arkaria.postgresql.org; Mon, 04 Feb 2019 16:19:35 +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 1gqgy6-00011s-VQ for pgsql-sql@lists.postgresql.org; Mon, 04 Feb 2019 16:19:35 +0000 Received: from mail.csaw.nl ([5.39.81.230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gqgy3-0002KT-Ul for pgsql-sql@lists.postgresql.org; Mon, 04 Feb 2019 16:19:33 +0000 Received: from [10.101.101.129] (BeLinked-3.iae.nl [212.61.45.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.csaw.nl (Postfix) with ESMTPSA id 1955D34041A; Mon, 4 Feb 2019 17:19:30 +0100 (CET) From: Sven Berkvens-Matthijsse Subject: Re: Idea: INSERT INTO ... NATURAL SELECT ... To: =?UTF-8?Q?Martin_St=c3=b6cker?= , pgsql-sql@lists.postgresql.org References: <4a9d68cd-4f6b-dbcf-c899-99fd2415f6b8@stb-datenservice.de> Message-ID: <7edf1575-d544-f643-e331-d340b26e87b4@berkvens.net> Date: Mon, 4 Feb 2019 17:19:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <4a9d68cd-4f6b-dbcf-c899-99fd2415f6b8@stb-datenservice.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: nl List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi Martin, On 01/02/2019 19.41, Martin Stöcker wrote: > Hi Sven, > > in many cases I prefer "copy from" to import data.  So I can create my > test data via spreadsheet and csv. Sure, that works, but it would then be useful if the COPY command would actually read the first line of a CSV file and use it to find the target columns in the table, but it does not. > Sometimes it is helpfull to do some shell stuff to create it or import > with psql. Yes, that definitely works. > But if you prefer to have column names and column data near to each > other, why not using json? > > postgres=#create table test ( i integer, t text); > postgres=# insert into test(select * from > json_to_recordset('[{"i":1,"t":"foo"},{"i":"7","t":"bar"}]') as x(i > int, t text)); That also works, but requires one to name all the columns and their types in the "AS x" part. That makes the statement very verbose. My proposal would not require the types to be stated and would only require the column names in the "data part" of the statement. > INSERT 0 2 > postgres=# select * from test; >  i |  t > ---+----- >   1 | foo >  7 | bar > (2 rows) > > Regards Martin Thanks for your thoughts! With kind regards, Sven