0

I don’t understand how to deal with schema changes and function definitions (which are by nature strings).

For example, if I have a table called tablename1 and/or a column called columnname1, and these are referenced throughout my functions, how should I go about updating my (many) functions when I delete or rename either one in my schema (for example to tablename2 or columnname2)?

I read this interesting Q&A.

My conclusion is that I should be using easily identifiable table/column names so that I may then easily Ctrl+F and replace in my favorite text editor the reference to those renamed tables or columns across all of the function definitions...

This sounds quite clunky and error prone, and I would imagine this need may occur often even in production environments?

I enjoy the benefits of Postgres functions and like to keep application logic as close to the database as possible but this seems like a reason not to do it? Or perhaps I am mistaken in changing tables and columns referenced in function bodies?

Andy
  • 1,307
  • 1
  • 12
  • 17
  • Find and replace is what you will have to do. – Adrian Klaver Aug 19 '23 at 15:22
  • "...and I would imagine this need may occur often even in production environments..." -- not really. It does happen but renaming a column or a table happens when your initial design was [substantially] defective; that happens from time to time; it's normal. Of course, for a change of this magnitude you'll need to find all affected resources, and adapt them accordingly. Searching the source code of the SQL and stored procedures is the way to go. Make sure it's versioned in the SCM. – The Impaler Aug 19 '23 at 17:28

0 Answers0