Re: Is there a good way to handle sum types (or tagged unions) in PostgreSQL?

Поиск
Список
Период
Сортировка
От Victor Nordam Suadicani
Тема Re: Is there a good way to handle sum types (or tagged unions) in PostgreSQL?
Дата
Msg-id CAHbE9O2ngKjVqR58vdR9FPk52tf=MqdzL7P5czryQg=g8twT4Q@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Is there a good way to handle sum types (or tagged unions) in PostgreSQL?  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список pgsql-general
A composite type is a product type, not a sum type. PostgreSQL currently has great support for product types, but basically no support for sum types. From the perspective of algebraic data types, this feels like a "missing link" in the type system. I'm not sure why SQL or the underlying relational model has never addressed this deficiency. Would greatly appreciate any insight anyone may have.

On Thu, 18 May 2023 at 16:35, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
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

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Unrecognized Node Type Warning
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: Would PostgreSQL 16 native transparent data encryption support database level encryption?