My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
1–10 of 10 posts
Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#2Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#3Aside from the SQL syntax, what is the difference between this and the longstanding virtual column feature, where you can define a function that takes the table's record type as input and return a scalar? PostgreSQL already let you use table.funcname as a virtual column, as I recall.
At least one demonstrable difference I can see between your recollection and this feature is that the column name being part of the DDL pushes the logic down into the DDL, versus every client having to carry that magic expression around with them. I think it's likely the age-old application-logic-client-side versus stored-proc camps
db=# select id, cast(length(name) AS text)||'0' as silly from my_table
as compared to > for the consumerRe: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#4Aside from the SQL syntax, what is the difference between this and the longstanding virtual column feature, where you can define a function that takes the table's record type as input and return a scalar? PostgreSQL already let you use table.funcname as a virtual column, as I recall.
It's possible the following argument is what you meant by "from the SQL syntax," and if so apologies for the noise At least one demonstrable difference I can see between your recollection and this feature is that the column name being part of the DDL pushes the logic down into the DDL, versus every client having to carry that magic expression around with them. I think it's likely the age-old application-logic-client-…
But if a function called silly with input type my_table existed, you could still do your second query. It has syntactic sugar for making a bare function name implicitly invoke on the current row record.
I can't remember if that sugar could also be used in an expression index. I never really used this syntactic feature, as I thought being more explicit with function calls would be better coding style.
Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#5Aside from the SQL syntax, what is the difference between this and the longstanding virtual column feature, where you can define a function that takes the table's record type as input and return a scalar? PostgreSQL already let you use table.funcname as a virtual column, as I recall.
Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#6Can’t wait!
Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#7Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#8Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#9You can, and probably should, do these things in your application code. I mean, it's not really that hard to make a string lowercase, you don't need to define a "virtual colum" for that...
Re: My Favorite PostgreSQL 18 Feature: Virtual Generated Columns
#10I don't really find these kind of features necessary. You can, and probably should, do these things in your application code. I mean, it's not really that hard to make a string lowercase, you don't need to define a "virtual colum" for that...