https://supabase.com/ logo
#help
Title
# help
p

Prodigy7kX

09/11/2021, 3:43 PM
Hey all, is there such a thing as "Virtual columns" or "Generated Columns" in Supabase?
s

silentworks

09/11/2021, 4:08 PM
Can you describe what these are or where could I get a reference to what they are supposed to be?
how can i make a code block?
`` A generated column is a special column that is always computed from other columns. Thus, it is for columns what a view is for tables. There are two kinds of generated columns: stored and virtual. A stored generated column is computed when it is written (inserted or updated) and occupies storage as if it were a normal column. A virtual generated column occupies no storage and is computed when it is read. Thus, a virtual generated column is similar to a view and a stored generated column is similar to a materialized view (except that it is always updated automatically). PostgreSQL currently implements only stored generated columns. ``
s

silentworks

09/11/2021, 4:23 PM
If its available in postgres then yes you can use it
p

Prodigy7kX

09/11/2021, 4:26 PM
bet, then i'll take a look on how to achieve what i wanna do
another question, since i don't remember seeing anything related to it in the UI, i guess i'll have to do it through the SQL editor, right?
s

silentworks

09/11/2021, 4:39 PM
Yes you will have to use the SQL editor#
p

Prodigy7kX

09/11/2021, 6:51 PM
Yeah, just tested it, it does work with SQL editor. but to insert any values to that table i also have to do it through the SQL editor, it won't me insert through the UI, it gave me an error:
Error: Error: cannot insert into column "height_in"
thats the table i created:
Copy code
CREATE TABLE people (
  height_cm numeric,
  height_in numeric GENERATED ALWAYS AS (height_cm / 2.54) STORED
);