Skip to content
Advertisement

How can I use a SET variable concisely in a DROP/CREATE/INSERT statements in PostgreSQL?

I have a template of a migration script that we run with new version when needed. It’s something like:

As you can see, the myapp.user value (someuser) is used at three places in the script.

  1. Is there a more elegant way to use myapp.user in the INSERT?
  2. How can I use myapp.user in the DROP TABLE and the CREATE TABLE statements?

I use PostgreSQL 9.4.14 if it changes something.

Advertisement

Answer

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement