如何在不使用CREATE CAST的情况下使外键成为两种不同的数据类型?

时间:2018-07-02 04:21:35

标签: postgresql heroku-postgres

我有两种类型的表:具有UUID主键的表和具有BIGINT主键的表。

我有一个特定的表,该表引用具有这两种类型的主键的表。

我不能使用CREATE CAST (character varying AS uuid) WITH INOUT AS IMPLICIT,因为我不拥有character varyinguuid(heroku)。

例如,假设使用这些表:

CREATE TABLE public.changelogs (
    id bigint NOT NULL,
    record_type character varying NOT NULL,
    -- record_id ??? NOT NULL,
    event character varying NOT NULL,
    actor_id uuid,
    transitions jsonb,
    object_changes jsonb DEFAULT '{}'::jsonb NOT NULL,
    created_at timestamp without time zone NOT NULL,
    group_id text NOT NULL
);

这两个表:

CREATE TABLE public.recipes (
    id uuid DEFAULT public.gen_random_uuid() NOT NULL,
    name text NOT NULL,
    slug public.citext NOT NULL,
    moderation_state public.citext NOT NULL,
    description text NOT NULL,
    author_id uuid NOT NULL,
    ingredients text[] DEFAULT '{}'::text[] NOT NULL,
    created_at timestamp without time zone NOT NULL,
    updated_at timestamp without time zone NOT NULL,
    instructions character varying[] DEFAULT '{}'::character varying[] NOT NULL,
    cook_time integer NOT NULL,
    prep_time integer NOT NULL
);

CREATE TABLE public.allergies (
    id bigint NOT NULL,
    name character varying NOT NULL,
    created_at timestamp without time zone NOT NULL,
    updated_at timestamp without time zone NOT NULL
);

0 个答案:

没有答案