OrientDB studio/console - How do I run batch script/javascript queries - orientdb

I want to run multi line queries/batch query, but it is not working both in studio and console in orientdb 2.2 community edition. is there something I need to do, I am sure something is missing at my end.
script sql
LET $a =
MATCH
{class:Member, as:m};
select expand($a.m);
end;

In v 2.2 the newline character is considered as a statement separator, so you have to write queries on a single line:
script sql
LET $a = MATCH {class:Member, as:m} RETURN m;
select expand($a.m);
end;
In v 3.0 it's not needed anymore, the only statement separator is the semicolon, so you can write multi-line queries in scripts.
To run a script in Studio, you have to select the BATCH mode in the menu at the bottom right corner of the query editor (near the "explain" button)

Related

Worksheet Editor bringing last character to newline when typing too fast

When i'm writing sql in sql developer and typing out a query quickly and do a new line, it'll bring the last character over to the new line and put my cursor behind the character.
SELECT *
SELECT
//cursor is here *

How do I collapse SQL in VS Code?

I checked the documentation for code collapsing, many languages have a marker defined but SQL doesn't.
SQL Server Management Studio recognizes begin and end as a region, allowing for folding, but VS Code doesn't.
Any suggestions are very appreciated.
For anyone coming here for the answer.
Region markers for SQL have been added to VS CODE in 2019 and you can now use them as:
--#region [name region if you like]
part of code you want to fold/collapse
--#endregion
Then use Ctrl + Shift + P or View -> Command Palette... and choose Fold All Regions.
use tab for group common code.
For example:
BEGIN
YOU SQL CODE
END
the region between BEGIN will be collapsed

pgAdmin query tool text highlights

Where is option for pgAdmin for highlights same words in query window?
That is, I need if selected word asd in query window, also checked/selected all asd words in this whole text.
In query tool window I not found anything for this.
pgAdmin ||| version 1.22.0 beta
So far, in version 1.22.2, there is no such feature. Alternatively, I use notepad ++ as the editor and then run on pgadmin.

Why are values copied from returned grid marked with quotes?

In PgAdmin III, when I copy value from returned grid and paste it into the query text, it appears there in double quotes. But to use it in query, in where clause for example, it has to be marked with apostrophe. So I have to replace quotes with apostrophe. It is rather weird for me that I always have to do so. Why it is designed in such strange way?
This is a kind of stupid theoretical question, I do not expect any practical answers :)
You can customize the quoting character, by following the following steps.
On the PgAdmin-III main window, click on File and then Options
Click on the Query Tool Tab
Change the field called "Result copy quote character" to apostrophe (')
It should work, you may need to close and open PgAdmin-III
EDIT: For Mac OS X the option could be found in pgAdmin3 > Preferences > Query tool > Results grid
For pgAdmin 4 go to File> Preferences> SQL Editor> Results Grid. You can change the Quotation mark to single quote or none.

How to see the CREATE VIEW code for a view in PostgreSQL?

Is there an easy way to see the code used to create a view using the PostgreSQL command-line client?
Something like the SHOW CREATE VIEW from MySQL.
Kept having to return here to look up pg_get_viewdef (how to remember that!!), so searched for a more memorable command... and got it:
\d+ viewname
You can see similar sorts of commands by typing \? at the pgsql command line.
Bonus tip: The emacs command sql-postgres makes pgsql a lot more pleasant (edit, copy, paste, command history).
select pg_get_viewdef('viewname', true)
A list of all those functions is available in the manual:
http://www.postgresql.org/docs/current/static/functions-info.html
select definition from pg_views where viewname = 'my_view'
If you want an ANSI SQL-92 version:
select view_definition from information_schema.views where table_name = 'view_name';
Good news from v9.6 and above. View editing are now native from psql. Just invoke \ev command. View definitions will show in your configured editor.
julian#assange=# \ev your_view_names
Bonus. Some useful command to interact with query buffer.
Query Buffer
\e [FILE] [LINE] edit the query buffer (or file) with external editor
\ef [FUNCNAME [LINE]] edit function definition with external editor
\ev [VIEWNAME [LINE]] edit view definition with external editor
\p show the contents of the query buffer
\r reset (clear) the query buffer
\s [FILE] display history or save it to file
\w FILE write query buffer to file
In psql cli , you can use
\d+ <yourViewName>
\sv <yourViewName>
Output as follows:
\d+ v_ma_students
View "public.v_ma_students"
Column | Type | Collation | Nullable | Default | Storage | De
scription
--------+-----------------------+-----------+----------+---------+----------+---
SOMETHINGS HERE
View definition:
SELECT student.sno,
student.sname,
student.ssex,
student.sage,
student.sdept
FROM student
WHERE student.sdept::text = 'MA'::text;
Options: check_option=cascaded
\sv v_ma_students
CREATE OR REPLACE VIEW public.v_ma_students AS
SELECT student.sno,
student.sname,
student.ssex,
student.sage,
student.sdept
FROM student
WHERE student.sdept::text = 'MA'::text
WITH CASCADED CHECK OPTION
These is a little thing to point out.
Using the function pg_get_viewdef or pg_views or information_schema.views you will always get a rewritten version of your original DDL.
The rewritten version may or not be the same as your original DDL script.
If the Rule Manager rewrite your view definition your original DLL will be lost and you will able to read the only the rewritten version of your view definition.
Not all views are rewritten but if you use sub-select or joins probably your views will be rewritten.
In the command line client psql you can use following command:
\sv <VIEWNAME>
The straightforward way to find the 'CREATE TABLE ...' query is to use this query -
SHOW TABLE your_schema_name.your_table_name