Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rKhHl-0044tl-3A for pgsql-general@arkaria.postgresql.org; Tue, 02 Jan 2024 16:06:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rKhHj-00GqVX-Pk for pgsql-general@arkaria.postgresql.org; Tue, 02 Jan 2024 16:06:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rKhHi-00GqVO-4d for pgsql-general@lists.postgresql.org; Tue, 02 Jan 2024 16:06:31 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rKhHe-00DONw-RI for pgsql-general@lists.postgresql.org; Tue, 02 Jan 2024 16:06:28 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 3D2FF5C01F1; Tue, 2 Jan 2024 11:06:25 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 02 Jan 2024 11:06:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1704211585; x=1704297985; bh=IDeE+zUENyqDjiHw60ygpkOpgvGItsRSJONn7vhtT00=; b= mHV68SD3sRGf5t13gm4xpd7mVt4b9HnMsj6TCRsA6rYbMnRD48ZkhiNQe3mrknLp 2iga1GSrZx4oyY81wKgT4P55Dvzt5Usf7QMIZOTHlB6GSkVRJHN8lqmJY5JheT5g cXakVJnMFJJfwamyIiM1EIIV5dZ8vNbOb+N1iTkIqrJ3wo+MVg7tOTkorGq2kkVP q84ZJrcqJlb4acvZa1KHWYAbdeeNuVktqZTR+8l8CqhgJnAzfL+Lj1jM5/SIf9A+ nrGKZNfwaG6Mja2l1h+zFwL32WeQH5LvNR8u7B8vo4CbvfAEs3K96zPP8SAwiHo9 XAvoQzyCFcXIBG2oToTG3Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1704211585; x= 1704297985; bh=IDeE+zUENyqDjiHw60ygpkOpgvGItsRSJONn7vhtT00=; b=6 B0jxNv/vWagf2YK2o0lYtC5dPcn1CafccsNc35QGt6mgN6TPiOb/qKttyZ4HeJET 36Y59cac5Ww/i3fOcUW95p0UBR6ncbkHok7ldkhyfnvJUJPWLwXYPWDa6Ru/fMxj qOz5myGjJXJgkZELY5cyYyra3gWm0PbIYk4nXFHWrjxoBLTYiUz14yL+YSlOnXtM EtF2adjSQGrnxCOxQxZvPsfBWIrYqoBIuuYZOCLuNyXhTt/F6voEAsUBew2ByAAH 0h06QACFZyzvXneteXjXWZUFJSyXK8u6TUxq5iebUHFtGsWMwy1sSYb18LvGPjYe fzuN/wsHD0zud+S/DTslQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdegfedgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepkeetveelheekudegudekleektdejheeiudevieev hedutdefiefgieetffekveeinecuffhomhgrihhnpehrvggrughthhgvughotghsrdhioh dpphholhgrrdhrshdpughutghkuggsrdhorhhgpdhphigurghtrgdrohhrghenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkh hlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 2 Jan 2024 11:06:24 -0500 (EST) Message-ID: <84b1254f-b409-44b8-a2cf-d5e4c0e8d828@aklaver.com> Date: Tue, 2 Jan 2024 08:06:23 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Import csv to temp table To: Daniel Verite , arun chirappurath Cc: pgsql-general@lists.postgresql.org References: <369a8ac6-e77d-4de6-878a-01eee781acaf@manitou-mail.org> Content-Language: en-US From: Adrian Klaver In-Reply-To: <369a8ac6-e77d-4de6-878a-01eee781acaf@manitou-mail.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/2/24 06:51, Daniel Verite wrote: > arun chirappurath wrote: > >> Do we have any scripts that create a temp table with column names >> from the first row of csv files? > > csvkit [1] does that. > > [1] https://csvkit.readthedocs.io/en/latest/ In addition to the above which I have used you might want to take a look at: Polars https://pola.rs/ and Duckdb https://duckdb.org/ They both allow you to query CSV(and other format) files directly. I have found them very useful for looking at CSV files and you can transfer data elsewhere later. Then there is: Pandas https://pandas.pydata.org/pandas-docs/stable/index.html which has read_csv(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html) and to_sql(https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_sql.html#pandas.DataFrame.to_sql) to pull from a CSV into a table. > > > Best regards, -- Adrian Klaver adrian.klaver@aklaver.com