Running saved scripts

When opening a saved sql file I can never just run it by using Command-Enter. I always get a message saying table not found.  I have to instead open a new console for the needed database and copy the sql there to run. Its no way to automatically attach a sql script to the currently selected db or either select a db?

0
5 comments

Hello Darrell,

When you run SQL the first time IDE offers you to choose the Data Source to associate with this file. You can change it later in status bar:
 

0

Hi Andrey,

it seems that you can only associate a script file with a database by executing the file. This is somewhat suboptimal. I think one of the benefits of associating a script file to a database is that IntelliSense and highlighting are then context-aware, right? It would make sense to have that benefit for existing files that you do not want to execute and new files that you are just creating.

Also, we have literally thousands of script files. They are in folders organized by database. So it would be nice to simply say associate this folder and all contained files to a database.

Another issue that I encountered lately is this: It seems like you can only associate script files with connections but not individual databases. The issue is that if you have multiple databases in one connection, you cannot control the database the file is executed in. My temporary solution is to have a seperate connection for each database.

0

Thank you for your feedback.

I think one of the benefits of associating a script file to a database is that IntelliSense and highlighting are then context-aware, right?

If no data source is associated with the sql file then IDE resolves DB objects from all Data Sources, configured in the project.

We have related request in YouTrack, please fote for: https://youtrack.jetbrains.com/issue/DBE-453 . I've added your feedback there.

Also, we have literally thousands of script files. They are in folders organized by database. So it would be nice to simply say associate this folder and all contained files to a database.

Btw, you can configure different scopes for these files and associate each with it's own color in Settings | Appearance & Behavior | File Colors settings.

0

Andrey, 

related to the first answer - yes, we can change connection, but will be very (very) good have also possibility to change and schema
like - if I have in one connection 2-3 schemas (development, testing or development with other data) I need run same script over several schemas on same (and different) servers.

 

0

I notice inconsistent behavior when first associating a sql file with a data source. Sometimes the data source does not show up on the bottom status bar until I toggle to another tab and back again. This appears to happen when there are multiple tabs open across more than one data source, however I have not been able to consistently reproduce the issue (os and dg version included below).

In addition to the feedback above, I feel that the current data source association would be improved by carrying through the data source color setting to the tab and window highlight (as it is for console files). This would greatly alleviate concerns that one may mistakenly run a script on an unintended source. Since I am switching amongst connections frequently, I resort to constantly detaching files to prevent any scripts from being inadvertently applied to the wrong connection.

I agree with the user feedback above, having the ability to associate a file with a db prior to executing would be much more straightforward. I find myself executing some simple statement (like 'SELECT TRUE;') just to get the file associated with a connection. As stated above, it would be nice to bulk associate files within folders as well.

 

I'm on OSX El Capitan 10.11.3

 

0

Please sign in to leave a comment.