by Antonio Linares » Tue Sep 03, 2024 10:32 am
To read a value from a .bat file into a .pgm file, you'll need to use a combination of batch scripting and PostgreSQL commands. Here's a step-by-step approach:
1. First, in your .bat file (mio.bat), set the value:
```batch
set cValue=1
```
2. Then, you need to pass this value to your PostgreSQL script. You can do this by using environment variables. Modify your .bat file to call the .pgm file and pass the variable:
```batch
set cValue=1
psql -f mio.pgm -v cvalue=%cValue%
```
3. In your .pgm file (mio.pgm), you can now access this value using the `:cvalue` syntax. Here's an example of how you might use it:
```sql
-- mio.pgm
SELECT :cvalue AS imported_value;
```
This will create a query that selects the value passed from the .bat file.