From b0588d39acdf7da21075c26685bf49bb8572a9dc Mon Sep 17 00:00:00 2001 From: Abhishek Date: Thu, 28 Sep 2023 15:41:25 +0530 Subject: [PATCH] doc_update/updating-doc-related-to-dsnexec-commnds-for-DDL-queries --- dsnexec/README.md | 5 ++++- dsnexec/config.yaml | 10 ++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/dsnexec/README.md b/dsnexec/README.md index 1429ba98..db6b7aef 100644 --- a/dsnexec/README.md +++ b/dsnexec/README.md @@ -35,4 +35,7 @@ Commands: args: An array of arguments to the SQL command. The args are parsed with the golang text/template package with the sources map as the - template context. \ No newline at end of file + template context. + (Note - If you intent to fire DDL queries, then put full go template expressions in the command. + As unlike for DML queries, underlying prepare statement does not consider arguments passed when the query is DDL.) + diff --git a/dsnexec/config.yaml b/dsnexec/config.yaml index ba184cb5..26f35a70 100644 --- a/dsnexec/config.yaml +++ b/dsnexec/config.yaml @@ -48,6 +48,12 @@ configs: driver: hotload dsn: fsnotify://postgres/path/to/myfile.txt commands: - - command: ALTER SERVER myserver OPTIONS (SET host=?); + - command: INSERT INTO table1 values ($1, $2); args: - - '{{ index . "test/source.json" "host" }}' \ No newline at end of file + - '{{ index . "test/source.json" "host" }}' + - '{{ index . "test/source.json" "port" }}' + + # As the below query is DDL, unlike insert (DML) written above, we can not pass arguments here. + # We need to put full go template expressions in the command itself + - command: ALTER SERVER myserver OPTIONS (SET host '{{ index . "test/source.json" "host" }}' ); + args: [] \ No newline at end of file