On Thu, 2025-05-29 at 11:12 -0400, Tom Lane wrote: > Perhaps a compromise is to invent RunAsUser but only apply it to > virtual columns for now, leaving the view case as a research > project. Then we aren't destroying the performance of any > existing queries.
Could we instead check that the expression is safe at the time the generated column is created? For the purposes of this thread, "safe" means "safe for the one running the SELECT". If the expression only involves functions and operators that are owned by the superuser (and/or in pg_catalog), or SECURITY DEFINER, then I think it's safe. It's not released yet, so we can start out more conservative (as long as it works for most use cases) and then make it a more precise check in the future. There are some details to work out. For instance, what happens if a function starts out as SECURITY DEFINER and then someone changes it later? Regards, Jeff Davis