Is there a way to configure data grip to convert 'ssf' into 'select * from' - datagrip

I type a lot of sql select statements. I'd like to be able to configure datagrip to replace the character string 'ssf' into 'select * from '. Is this possible?

It is, go to Settings | Editor | Live Templates where you can create snippets.
But see that there are templates already!
So, sel is actually will be transformed into SELECT * FROM.
To try this, type sel and press TAB.

Good news, it is possible to configure DataGrip to replace a specific string with and expanded string! What other editors (Sublime, VS Code, SSMS, Azure Data Studio, MySQL Workbench) call "snippets," DataGrip and other JetBrains products call "Live Templates" as described for WebStorm here.
There is an existing snippet for what you ask to do, which when expanded will also leave the cursor in the correct location for you to immediately start entering the desired source.
As #moscas mentions in his answer, the live template sel is what you are looking for.
When sel is typed, followed by Tab (or what your DataGrip "By default expand with" setting is) sel will expand to
> `SELECT * FROM ...;`
The cursor will be where the ellipsis (...) is after the expansion. Other useful existing templates are listed here and I recommend building muscle memory for selc and selw. I also created a selt for SELECT TOP(10) * FROM ...; and you should be able to create a new one with using the ssf string using resources linked.
Here are the other default snippets/Live Templates that ship with DataGrip and expand with default expansion:
+---------------------------------------------------------------+
| Abbreviation | Expands to |
+---------------------------------------------------------------+
| ins | INSERT INTO ... (...) VALUES (...);" |
| sel | SELECT * FROM ...;" |
| selc | SELECT count(*) FROM ... alias WHERE alias. ...;" |
| selw | SELECT * FROM ... alias WHERE alias. ...;" |
| upd | UPDATE ... SET ... = ... WHERE ...;" |
+---------------------------------------------------------------+

Related

How to remove PhpStorm auto added text on the codes

Does anyone knows how to remove the word "url" & "view" which is automatically added on the PHP storm IDE?
Check below image I have marked in red:
They are called inlay hints, you can find the settings for them here:
Phpstorm 2017.1:
Editor | General | Appearance | Show parameter name hints
Phpstorm 2019.3:
Settings | Editor | Inlay Hints | PHP | Parameter hints

How to work with packages in Liquibase

We use liquibase with oracle. So we have some packages with procedures inside.
In our case changelog structure looks like:
master.xml
|
| release1
| |
| release-maser.xml
| release2
| |
| release-maser.xml
| softObjects
| |
| package-master.xml
| packages
| |
| somePackage.pkb
| somePackage.pks
change sets inside "releases" with runOnChange=false and "softObjects"(that can be create used CREATE OR REPLACE) with runOnChange=true like in best practices:
Try to maintain separate changelog for Stored Procedures and use
runOnChange=”true”. This flag forces LiquiBase to check if the
changeset was modified. If so, liquibase executes the change again.
So every update intall some "delta" change sets from "release" and AFTER reinstal all "softObjects" that was changed and in usual case all is OK.
But if I need to setup new DB, I will get a problem:
in change set from second release I use somePackage(v1), but in next release i need to change logic/API somePackage so I will get somePackage(v2) that can not be used in previously created change sets. So for now I have change set that on update will try to use wrong package version.
For avoid this I can add soft objects directly inside release folder without runOnChange=true when i create it. When I need to change it, i should just copy previous version of file to my new release and make changes inside a COPY.
This approach has some disadvantages:
you make a lot of copy files that can consist from thousands lines of
code(yes I know that it isn`t good)
version control system recognize it as a new file (good challenge for
reviewers)
What i undestand wrong? How should I work with "softObjects", if this objects might be changed?

ERROR 1064 (42000) at line 38: check the manual that corresponds to your MySQL server version for the right syntax to use near '//

I am trying to run a mysql script on centos. I have following mysql installed.
mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------------------------------+
| innodb_version | 5.6.25-73.1 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.6.25-73.1 |
| version_comment | Percona Server (GPL) |
| version_compile_machine | x86_64 |
| version_compile_os | Linux |
+-------------------------+------------------------------------------------------+
My sample script looks like:
DELIMITER //
DROP TRIGGER IF EXISTS trg_table1_category_insert;
DROP TRIGGER IF EXISTS trg_table1_category_update;
CREATE TRIGGER trg_table1_category_insert
AFTER INSERT
ON
table1_category
FOR EACH ROW
BEGIN
insert into table1_category_history (
table1_category_history_id,
table1_id,
transaction_start_date
) values (
new.table1_category_id,
new.table1_id,
new.create_date
);
END;
//
CREATE TRIGGER trg_table1_category_update AFTER UPDATE on table1_category FOR EACH ROW
BEGIN
insert into table1_category_history (
table1_category_history_id,
table1_id,
transaction_start_date
) values (
new.table1_category_id,
new.table1_id,
new.create_date
);
END;
//
DELIMITER ;
My database utilizes utf8 encoding. While importing this file in database on mysql client it keeps throwing
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '//
CREATE TRIGGER trg_table1_category_update AFTER UPDATE on ta' at line 1
I do not see any syntax error while using the delimiter, also it works on some machines absolutely fine, i have googled almost 100s of links and tried all the ways with downgrading/upgrading mysql server/client , my.cnf, charset etc it is not helping me out. Can anyone please help me on this? Can there be any settings done at client level to interpret it correctly.I am using the same version client that comes with mysql server installation.

squirrelsql doesn't like query_to_xml

I am using an SQL that includes query_to_xml:
select query_to_xml('select 1+1 answer', true, true, '') as_xml;
When any SQL with query_to_xml is executed in Squirrel SQL it will result in:
| as_xml |
+--------------------+
|<UnknownType (2009)>|
With the same JDBC driver, credentials and a Java class the SQL will result in the expected XML output:
| as_xml |
+------------------------------------------------------------+
| <row xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">|
| |
| <answer>2</answer> |
| </row> |
I can execute other functions in Squirrel and they will respond, like select version().
Is this a known feature in Squirrel?
If you are using the latest squirrel client, Go to File, Global Preferences-> Data Type Controls, check the box under Unknown DataTypes section.
Rerun the query, it might work.
It seems to be an issue with the text option output for SQL results. It works if you change to the tabular output. Go to the Session menu and click "Session Properties". On the "General" tab under "Output" change "SQL Results" from Text to Table and rerun the query. You may need to close the existing results tabs first.
If this fixes it please add a bug report so that it can be fixed in the future.

Formatting output from RubyDatamapper similar to SQL

Running a select statement in psql returns output nicely formatted in a table:
mydb=# SELECT * FROM users WHERE login = 'foo';
id | login | first_name | last_name
------+-------+------------+------------
1000 | foo | Dude | HowdyHeyYo
However, I often run my database queries in IRB, and use datamapper to connect to Postgres. What's the best way to get the output formatted similarly to the above table when running a query like this using Ruby and Datamapper?
>> User.all(:login => 'foo')
psql is formatting the output into the ASCII table layout. psql is the equivalent to IRB at that point, so you'd either have to write a method to call that would wrap your query and output formatted results, or use some IRB plug-ins.
Take a look at IRBTools and, in particular, hirb.

Resources