# Liquibase resolves/interpolates environment variables in SQL files

**URL:** <https://forum.liquibase.org/t/liquibase-resolves-interpolates-environment-variables-in-sql-files/9128>\
**Category:** Uncategorized\
**Created:** [February 20, 2024, 8:34am UTC](https://forum.liquibase.org/t/liquibase-resolves-interpolates-environment-variables-in-sql-files/9128 "2024-02-20T08:34:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielplatz83](https://avatars.discourse-cdn.com/v4/letter/d/e5b9ba/32.png) [@danielplatz83](https://forum.liquibase.org/u/danielplatz83)\
**Post date:** [February 20, 2024, 8:34am UTC](https://forum.liquibase.org/t/liquibase-resolves-interpolates-environment-variables-in-sql-files/9128/1 "2024-02-20T08:34:27Z")

</div>

I have an SQL file like this with a variable:

```auto
INSERT INTO ATABLE VALUES ('${MY_VAR}');

```

I set on my shell

```auto
export MY_VAR=ABC

```

Now I run liquibase.sh to apply my SQL to the DB. I can see that in my database it contains the value ‘ABC’.

I can see from the documentation that this mechanism is supported [1](https://docs.liquibase.com/concepts/changelogs/property-substitution.html), but documentation states it should only do this for variables starting with ‘LIQUIBASE\_’. Why is it still doing it for my variable?

I am asking because we are seeing this replacmenent of environment variable in an inconsistent manor. It happens for some variables but others not and i would like to understand what is expected from liquibase product side. Should it replace random variables that do not start with the LIQUIBASE\_ prefix or not?

I also see [this thread](https://forum.liquibase.org/t/passing-runtime-variables-to-sql-files/4331) that suggests that it will replace any environment variables but to me it does not align with what is in the documentation.

Using liquibase: org.liquibase:liquibase-core=4.20.0

---

<div class="post-metadata">

**Author:** ![phreakadelle](https://avatars.discourse-cdn.com/v4/letter/p/ecd19e/32.png) [@phreakadelle](https://forum.liquibase.org/u/phreakadelle)\
**Post date:** [February 29, 2024, 9:44am UTC](https://forum.liquibase.org/t/liquibase-resolves-interpolates-environment-variables-in-sql-files/9128/2 "2024-02-29T09:44:37Z")

</div>

I am having the same issue over here. I always need to run the liquibase scripts from a subshell to de-couple it and avoid the liquibase.sh script to replace my ${MyVariable} in the sql scripts. We like to evaluate those variables during the runtime of our app and not during the execution of the database scripts.

Would be interested in clarity as according to the documentation only LIQUIBASE\_ prefixed varibales should be resolved.

---

<div class="post-metadata">

**Author:** ![matthieu-marechal](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@matthieu-marechal](https://forum.liquibase.org/u/matthieu-marechal)\
**Post date:** [September 25, 2024, 12:56pm UTC](https://forum.liquibase.org/t/liquibase-resolves-interpolates-environment-variables-in-sql-files/9128/3 "2024-09-25T12:56:46Z")

</div>

I agree that liquibase shouldn’t interpolate just any varables. However, there is another workaround than a subshell: From the docs:  
**Note:** If you do not want to replace an otherwise matching `${property-name}` expression, add `:` to the beginning of the expression. An expression of `${: property-name}` will always be converted to `${property-name}` regardless of whether `property-name` is defined.

---

<div class="post-metadata">

**Author:** ![matthieu-marechal](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@matthieu-marechal](https://forum.liquibase.org/u/matthieu-marechal)\
**Post date:** [September 25, 2024, 1:07pm UTC](https://forum.liquibase.org/t/liquibase-resolves-interpolates-environment-variables-in-sql-files/9128/4 "2024-09-25T13:07:51Z")

</div>

I see now it is documented at the examples:

> **[Substituting Properties in Changelogs](https://docs.liquibase.com/concepts/changelogs/property-substitution.html?_ga=2.106529478.410176247.1727267873-308801832.1706683019#sql_example)**
>
> Liquibase allows dynamic substitution of properties in your changelog. The tokens to replace in your changelog are described using the ${property-name} syntax.

So, it would be hard to change (perhaps behind a flag).
