PLSQL How to execute other scripts from a script?

Its been almost a decade since this was asked, is this still the case?

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000003430-Execute-SQL-script-with-a-list-of-scripts-files-inside

 

I would like to move from Toad or SQL Developer to Datagrip, but cannot seem to execute scripts that use the @@ reference.

@@set_variables.sql
@@script1.sql

//update tableA

@@script2.sql
@@script3.sql

//update tableB

@script4.sql

 Currently, after setting the dialect, it recognizes the actual sql in the main script but just ignores all script references.  Am I missing something on how to do this?

0

Nicholas Aupke, at the moment DataGrip users a bit different paradigm of Run Configurations where you can set a desired order.

1

I would like to use the Run Configuration feature to simplify rebuilding my database. I have two scripts - one that drops and recreates the schema (including all tables) and another that regenerates all views. Both include “use” statements.

In the Run/Debug Configurations dialog, I get a warning that my scripts contain schema switches, which is OK. However, even when I select a data source (DB server) only (no schema), I still see these warnings. It seems that if only a data source is selected, the warnings should not apply.

 

0
Hi,

Yes, that's a warning you'd get when switching schemas in your script:

https://www.jetbrains.com/help/datagrip/run-sql-files.html#run_sql_file

Please provide a sample of your script where schema switching is not applied. You can just include basic statements without specifying routine details.

We'll have a look.
0

Thank you for the response. I understand the need for the warning when a schema is selected as part of the data source. I am just wondering if the warning should be displayed when a schema is not selected. In that case, the script would be required to contain “use” statements, so perhaps it should not trigger a warning in this configuration.

 

0
I have just run a MSSQL script with use statements where I used different databases, but couldn't catch any warnings in the output in 2024.1.1 version. May I know your   current IDE version and the database over which you executed your script  from Run Config section?
0

The warnings are in the dialog, not the script output.

As you can see, I have not selected a schema in my configuration. My scripts would therefore have to include a “use” statement, or they would not work. I am suggesting that the UI not display the warning icon in this case. In fact, it might actually make more sense to display a warning if a script does not include a “use” statement when no schema is selected.

0
Thanks, we were able to reproduce it.

We'll follow up with more information soon.
0
As it's turned out, this is an expected behavior and should behave this way by default. However, according to your screenshot, you're either connecting to a server directly without specifying a schema in the URL, or the data source is not introspected. Normally, it would prompt for a default schema. There were some issues with the way USE statement is applied to MSSQL databases in the run config scripts - the warning is also shown in this case. We'll fix the missing spots.
0

Thanks for the update. I actually don't want to be prompted for the schema, since my script drops the schema and re-creates it. I use this feature to ensure that I have a clean database before kicking off a test run. Prompting for the schema would break my workflow.

 

0
You should not get any prompt during the execution. It's just a warning informing you about using other schema. It should break your workflow due the execution of both scripts.
0

OK, thank you for confirming.

0

请先登录再写评论。