I am trying to write a script to run in DBeaver (Version 24.0.0) it determines what schema update scripts to run based on a table in the database that records the schema updates already run. It then tries to use the dbeaver @include to run the needed update scripts.
It looks something like: **
**@set db_dir = '<path of update scripts>'
<code that inserts into a temp table, upgrade_files, the filenames of the schema update files not already recorded in the database>
do $$
DECLARE
file upgrade_file%ROWTYPE;
file_location text;
BEGIN
FOR file in (select * from upgrade_files) loop
file_location = ${db_dir} ||file.filename;
raise info 'file: %', file_location;
@include ${file_location}
end loop;
end $$**;
**
If I run this I get "Syntax error at or near @".If I comment out the @include statement in the for loop it runs fine and prints out the correct filenames, including path, to be run. Any help figuring out what I am doing wrong or another approach would be appreciated.
1 Answer 1
You are mixing up DBeaver syntax with that of what appears to be Postgres' PL/pgSQL. The entire DO $$ ... $$
block gets sent to the Postgres server for execution, and Postgres has no idea what @include
means, because it's apparently a DBeaver thing.
Use one programming concept at a time.