Working with sql files

Hi.

I'm new to IntelliJ, so I apologize in advance if I misunderstand the concept on how to work with sql (files) via IntelliJ Ultimate. 

In my daily work I have to deal a lot with databases, this also means that I have to query sometimes the same information again and again. Hence I store those queries usually in sql files. 

So if I happen to use IntelliJ to write a query in the console and like to save/export it to a file I can only use F5 or Refactor -> Copy. For this I had to search through your filetracker https://youtrack.jetbrains.com/issue/IDEA-134312. I don't understand why the sql console toolbar doesn't have an action "Save" or "Save As"? I find this not really intuitive and many of my colleagues didn't even know that it was possible to save the content of a sql console to a file.

I have a similar issue when trying to load/open an existing sql file from the filesystem. The sql console doesn't have an action to load the content of an existing file into it. So by using File -> Open I can open it and I can execute the content. However I don't understand why the content is not automatically loaded into a sql console window but I would have to do this myself by using the shortcut or the action in the db view. 

I find this simple topic rather strangely solved not only in IntelliJ but in DataGrip as well. Is there a particular reason why it is as it is or is this a work in progress thing?

Thanks in advance!

6 comments
Comment actions Permalink

Thanks for the feedback, I've forwarded it to DataGrip team.

0
Comment actions Permalink

SQL consoles are ordinary files. They are shared between projects like data sources, support VCS and Local history.

One can copy a console file path to clipboard with "Copy file path" action (Ctrl-Shift-C) directly from editor, Scratches view or NavBar.

Documentation page: https://www.jetbrains.com/idea/help/database-console.html .

0
Comment actions Permalink

Hello Gregory.

Thank you for your reply. I get the feeling that you did not take the time to read through my original post. Since you did not answer any of my questions.

First of all, I consulted your documentation, google and my colleagues before I posted this. Unfortunately none of my questions were answered. The only information I found about saving was https://youtrack.jetbrains.com/issue/IDEA-134312 .

I simply try to understand why the sql console doesn't provide a save/save as action in its toolbar and why do sql files not open automatically in a sql console?

Thanks in advance!

0
Comment actions Permalink

Hello Stefan,

May be I do not quite understand your use case, but what is the benefit of having Save Action in SQL Console toolbar if the action is available in File menu?

As for automatically opening sql file in database console. There is an action to run content of the sql file in the database console (via Alt+Enter intention action):

 

After which this file is associated with specified Data Source. You can change this association later:

 Does it help?

0
Comment actions Permalink

Hello Andrey.

Thank you for your reply! I got from your screenshots already on answer which explains perhaps already part of my confusion. DataGrip and IntelliJ come by default without enabled Main Toolbar. This explains why a 'Console / Console File' doesn't have that action in their toolbar.

Unfortunately IntelliJ doesn't have the 'Files Windows' it only exist in DataGrip. But I can simply open SQL files through the file menu or toolbar.

The only question I have left for the open sql files topic: Why opens the content of an sql file not automatically within a 'Console / Console File'?

The save topic is still a bit confusing. Yes, DataGrip has an action in the main menu 'Save As' strangely a as dialog opens which says copy instead of 'Save As'. However IntelliJ doesn't have this action in its Menu. There I can only use F5 or Refactor -> Copy.

One thing I don't understand in this context either. Why are changes when editing an open sql files automatically saved, but when modifying the content after loading it into a 'Console / Console File' it's not?

Thank you for your help and patience!

0
Comment actions Permalink

What I've found is that I can save SQL in a directory, and then in DataGrip's FILES tab, "attach" that directory. Double-clicking loads the script. Running prompts for the database connection to use when running the script. A little different from another tool I've used for 15 years, but easy and really rather nice. 

I am new to DataGrip; I am really liking it's capabilities.

0

Please sign in to leave a comment.