pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Victor Nordam Suadicani <v.n.suadicani@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Is there a good way to handle sum types (or tagged unions) in PostgreSQL?
Date: Thu, 18 May 2023 07:35:08 -0700
Message-ID: <a585c794-81de-6470-e968-4f52db1567d8@aklaver.com> (raw)
In-Reply-To: <CAHbE9O3RAR+J2bvA47rLbkTmUpV_U7ctr-rHjDPA+77GCs-=EQ@mail.gmail.com>
References: <CAHbE9O3RAR+J2bvA47rLbkTmUpV_U7ctr-rHjDPA+77GCs-=EQ@mail.gmail.com>

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






view thread (6+ messages)  latest in thread

Message-ID: <a585c794-81de-6470-e968-4f52db1567d8@aklaver.com>
Permalink:  ../a585c794-81de-6470-e968-4f52db1567d8@aklaver.com/
Also on:    postgresql.org/message-id/a585c794-81de-6470-e968-4f52db1567d8@aklaver.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, v.n.suadicani@gmail.com
  Subject: Re: Is there a good way to handle sum types (or tagged unions) in PostgreSQL?
  In-Reply-To: <a585c794-81de-6470-e968-4f52db1567d8@aklaver.com>
  References: <CAHbE9O3RAR+J2bvA47rLbkTmUpV_U7ctr-rHjDPA+77GCs-=EQ@mail.gmail.com> <a585c794-81de-6470-e968-4f52db1567d8@aklaver.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox