plmustache icon indicating copy to clipboard operation
plmustache copied to clipboard

Dependency tracking

Open steve-chavez opened this issue 2 years ago • 0 comments

BEGIN ATOMIC works like this right now:

create table person (
	firstname text,
	lastname text
);

create function foo(person) returns text begin atomic select $1.firstname || $1.lastname; end;

select foo('(x,y)');
 foo 
-----
 xy
(1 row)

After a column rename, the function keeps working:

alter table person rename column lastname to last_name;

select foo('(x,y)');
 foo 
-----
 xy
(1 row)

This because it automatically updates the function body:

\df+ foo

BEGIN ATOMIC                               +
 SELECT (($1).firstname || ($1).last_name);+
END                                         

If the foo function were to be created with language sql, it wouldn't work that way:

create or replace function foo(person) returns text as $$
	select $1.firstname || $1.lastname;
$$ language sql;

select foo('(x,y)');

ERROR:  column "lastname" not found in data type person
LINE 2: select $1.firstname || $1.lastname;

Not sure if we can achieve the BEGIN ATOMIC behavior, but could we at least fail if a column is renamed? Maybe by inserting an entry into pg_depend?

This will make more sense once https://github.com/PostgREST/plmustache/issues/2 is done.

It would also be a compelling reason to do HTML rendering on the database.

steve-chavez avatar Sep 10 '23 17:09 steve-chavez