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 1iYHji-0005Ga-B6 for pgsql-general@arkaria.postgresql.org; Fri, 22 Nov 2019 22:49:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iYHjf-0007TA-7M for pgsql-general@arkaria.postgresql.org; Fri, 22 Nov 2019 22:49:07 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1iYHjd-0007T3-7L for pgsql-general@lists.postgresql.org; Fri, 22 Nov 2019 22:49:06 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iYHjU-00030y-HA for pgsql-general@postgresql.org; Fri, 22 Nov 2019 22:49:04 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 89512E6B; Fri, 22 Nov 2019 17:48:52 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 22 Nov 2019 17:48:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=A DmNCJt/kb0mQMnyilOm+itv6r4CZKtGcHGlmdItoKg=; b=qMWFc6y6IykG+sh8D VM67Z+JSjUXeZkulimjb/bSu2rYM8Eqo9G6k8J+gMQa+pK14nMHHHGd9X1PJBY19 cNHQzK9t0H2PX6p47jJqa4aRTS06uQ46iXs0jlUsxtyFQkGD+N2BOf8PzmCRjIPW 4MG6JmJSoJmD0DV1oXF7Xyg0jsHdAbHd4DJU/+X3tFdRwGkDOeOkBh8nqvJTkm6O pyJB+OjZruMMCBRNUqG4EAVsEE6oZc0OayMbz2tQzGPPHK5xWnKoEqaYinLUbYFb wDD31sGQebI8ff4VFf1MHsW3OEergAn7P6ToHk/+WzMGVlAfL3/6lZG/qvYjMMhR Cx7gw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=ADmNCJt/kb0mQMnyilOm+itv6r4CZKtGcHGlmdIto Kg=; b=xlGUPaZ8bVN1WQ9xZ50gv4n1+4GWJcwDySVfIwnSudxkdBYemqPte3j6U Iseb0EENIoIvQvEwiHbBScCP7Pki7376LZdwnV2KTjskr20CFOr0pZ0RbVSCg8Iw FSfW8aUD+soLZ0+pzhePoH2wyUEjv93z+0oU5MrZlR52IDSOev8gJsGIY0iKVljG mevKccwn5FhgORAVyZMj431zveOF78TRBxaQ+Ar2f4/fA1vhsAa27UIkju6SrI58 E8K95b2NKrVDigBqAB6Rr3f7haiLR1MRl7XYKjiJ4ZZHYOT0GWJi07NC1Q+JRVGx f53yqqpKuUodm7hfmSUP7erwOhiaQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudehhedgtdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucfkphepjedurddvuddvrddufeefrdduudeknecurfgrrhgrmhepmhgrihhlfhhr ohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsth gvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.2] (unknown [71.212.133.118]) by mail.messagingengine.com (Postfix) with ESMTPA id 72DC680064; Fri, 22 Nov 2019 17:48:51 -0500 (EST) Subject: Re: automated 'discovery' of a table : potential primary key, columns functional dependencies ... To: =?UTF-8?Q?R=c3=a9mi_Cura?= , PostgreSQL General References: From: Adrian Klaver Message-ID: <80d60035-6c4a-4eac-df16-956fc49901e8@aklaver.com> Date: Fri, 22 Nov 2019 14:48:50 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/22/19 2:05 PM, Rémi Cura wrote: > Hello dear List, > I'm currently wondering about how to streamline the normalization of a > new table. > > I often have to import messy CSV files into the database, and making > clean normalized version of these takes me a lot of time (think dozens > of columns and millions of rows). To me messy means the information to do the below is not available. Personally I think you best bet is to get the data into tables and then use visualization tools to help you determine the below. My guess is there will be a lot of data cleaning going on before you can get to a well ordered table layout. > > I wrote some code to automatically import a CSV file and infer the type > of each column. > Now I'd like to quickly get an idea of >  - what would be the most likely primary key >  - what are the functional dependencies between the columns > > The goal is **not** to automate the modelling process, > but rather to automate the tedious phase of information collection > that is necessary for the DBA to make a good model. > > If this goes well, I'd like to automate further tedious stuff (like > splitting a table into several ones with appropriate foreign keys / > constraints) > > I'd be glad to have some feedback / pointers to tools in plpgsql or even > plpython. > > Thank you very much > Remi > > -- Adrian Klaver adrian.klaver@aklaver.com