Hi peopleđź‘‹ just wondering what would be the recom...
# off-topic
n
Hi people👋 just wondering what would be the recommended approach to implement Select/Enum type in supabase tables. Thanks🙏🏼
u
I usually create separate table with the options to choose from then set a foreign key reference
Copy code
— table for the options
create table select_options (
  id uuid primary key default uuid_generate_v4(),
  name text not null
);

— some other table
create table other_table (
  select_option_id uuid references select_options not null
);
t
there's a nice trick mentioned in "SQL Antipatterns" by Bill Karwin (the chapter was "don't use Enum" 🙂 )
Copy code
create table options (
  option_type varchar primary key
);
create table items (
  id bigint primary key,
  option_type references options
);
insert into options (option_type) values ('allowed'), ('allowed_as_well');
it's quite convenient, as you get to control what values are accepted, you keep your relational guarantees, it stays readable and you get to save quite a bit of joins