Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pzeir-00021N-Dt for pgsql-general@arkaria.postgresql.org; Thu, 18 May 2023 14:35:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pzeiq-0004Ua-Ba for pgsql-general@arkaria.postgresql.org; Thu, 18 May 2023 14:35:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pzeio-0004Oi-Uk for pgsql-general@lists.postgresql.org; Thu, 18 May 2023 14:35:16 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pzeil-000VGo-7T for pgsql-general@lists.postgresql.org; Thu, 18 May 2023 14:35:13 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 031B65C0116; Thu, 18 May 2023 10:35:10 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 18 May 2023 10:35:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= 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:sender:subject:subject:to:to; s=fm3; t= 1684420509; x=1684506909; bh=vLozFwNE4TMcxhU8S6rW3xV+8rq+BFj38Qr BGASIpag=; b=jbQ+Nz5dGX0kaq1FiG9XOOVg2uLKBGCGaYlc0TvaxlJAqKv6jH2 vGUh/622q7wP/pfnlBaGn8omhwagKxU32DDaPrBPdr0GQu3lkxOKRN8BtoPY1m1h uwd9428MY6uHH9AzoNmMUAxnVj5FWe7ZMDCzKvqy5Amg2R9G1EnNxl0rzD+FKu/V lU90kj0X/lDQHJ6FccaEdtHsJrkA1HhJdQesG3yaIn+CWuzLaL69F/gxRJ+jfuVp deBduntQp7QLM9/8LW5Nto1Ja8oSdAds5ojiG3Y1fcjQejk33ExwA7VVn6RAbHEK TxOcgOvuCvFPthGjHkNobxRiSNAb4SG71Yg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1684420509; x= 1684506909; bh=vLozFwNE4TMcxhU8S6rW3xV+8rq+BFj38QrBGASIpag=; b=m 1SIC01tsfTWAnZ6qTe/q9dkDla8BPtpb9JiBAAdcORjPoAYzf+eKX/NX4W1eJoOk tCug+yytijT4oQynuw82kIlP3sDf/RD09zJgFHHxf/3MkBXp3XOyJTHRmzIYhGtQ +w/P/39E+xt5sa4OIdYcEC2q3avLkf82PmzlQJYgFlTZAZjkahGLjJyzhVihu/Xs Ao1F2EBY49ED14G51DFLNEs/eikkLuFE+OsZyp1eXxhTvUXaiEK4dS/x7R2sXkd/ dBi9tuImCHSiiVFvkcglmawBMFyAZv4KmYl7K8zhHTAVujjvEUegYssICmKjm3nL 5fyQX4s6/CYlVeTnNWHtg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeeifedgjeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelkeegjefhkeetheefudevteehiedvudehkeduleet fedvffeuhedtvdegtdeffeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 18 May 2023 10:35:09 -0400 (EDT) Message-ID: Date: Thu, 18 May 2023 07:35:08 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: Is there a good way to handle sum types (or tagged unions) in PostgreSQL? To: Victor Nordam Suadicani , pgsql-general@lists.postgresql.org References: Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/18/23 05:27, Victor Nordam Suadicani wrote: > Hi, > > Is there any nice way to handle sum types (aka tagged unions) in a > PostgreSQL database? I've searched far and wide and have not reached any > satisfying answer. > > As a (somewhat contrived) example, say I have the following enum in Rust: > > enum TaggedUnion { >     Variant1(String), >     Variant2(i32), >     Variant3(f64), > } > > If there are no good methods of handling this, is there any way > PostgreSQL could be extended with capabilities for this? I have no idea > how this would be done in practice though. Perhaps SQL itself is just > unsuited for data of this kind? I don't really see why it should be though. Composite type?: https://www.postgresql.org/docs/current/rowtypes.html > > Thanks, > Victor Nordam Suadicani -- Adrian Klaver adrian.klaver@aklaver.com