I had created many classes with properties in orient Db. Now i want to retrieve only the property information.
In MySQL we are using query "desc table Name'
in orient Db which query is used to get the property details with out the data embedded in it.
Try:
select #type, #rid, #version, #class from v
where v is your class.
You might be interested in example query for metadata as documented in http://orientdb.com/docs/2.2/SQL.html#query-metadata
You can retrive property name with :
select name from (select expand(properties) from ( select expand(classes) from metadata:schema ) where name = 'OUser')
+----+--------+
|# |name |
+----+--------+
|0 |status |
|1 |password|
|2 |name |
|3 |roles |
+----+--------+
Related
In SQL Server it's possible to do inline variable assignment.
For example, table dbo.tblSynonym:
+--+-------+-----------+
|id|keyword|replacement|
+--+-------+-----------+
|1 |aaa |bbb |
|2 |xxx |yyy |
|3 |ddd |eee |
+--+-------+-----------+
when I run this:
DECLARE #body varchar(max)='aaa111xxx111ddd'
SELECT #body = REPLACE(#body,keyword,replacement)
FROM dbo.tblSynonym
SELECT #body
The result should be bbb111yyy111eee.
So the value of #body will be updated on each row (interaction) and the replace input will be from result of previous rows on the source table.
Is it possible to do something like this in postgres (without cursor)?
Thanks
I think this will help you
regexp_replace('Thomas', '.[mN]a.', 'M') //ThM
Look here
https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
I use Orientdb 2.2.35. I insert some documents into it until a conflict occurs.
When I check the record version, it didn't change during the insertion (After conflict). In my example you can see the version of #18:0 after I insert an edge (create edge mye from #18:0 to #19:0)
Error:
com.orientechnologies.orient.core.exception.OConcurrentModificationException:
Cannot UPDATE the record #18:0 because the version is not the latest.
Probably you are updating an old record or it has been modified by
another user (db=v2 your=v1)
orientdb {db=TestDB}> select * from #18:0
+----+-----+------+----+------------------------------------------------------------------------+
|# |#RID |#CLASS|id |out_MyE |
+----+-----+------+----+------------------------------------------------------------------------+
|0 |#18:0|MyV |1 |[#22:0,#22:1,#22:2,#22:3,#22:4,#22:5,#22:6,#22:7,#22:8,#22:9(size=5000)]|
+----+-----+------+----+------------------------------------------------------------------------+
1 item(s) found. Query executed in 0.002 sec(s).
orientdb {db=TestDB}> load record #18:0
DOCUMENT #class:MyV #rid:#18:0 #version:2
+----+-------+------------------------------------------------------------------------+
|# |NAME |VALUE |
+----+-------+------------------------------------------------------------------------+
|0 |id |1 |
|1 |out_MyE|[#22:0,#22:1,#22:2,#22:3,#22:4,#22:5,#22:6,#22:7,#22:8,#22:9(size=5000)]|
+----+-------+------------------------------------------------------------------------+
OK
orientdb {db=TestDB}> create edge mye from #18:0 to #19:0
+----+--------+------+-----+-----+
|# |#RID |#CLASS|out |in |
+----+--------+------+-----+-----+
|0 |#22:5250|MyE |#18:0|#19:0|
+----+--------+------+-----+-----+
Created '1' edges in 0.017000 sec(s).
orientdb {db=TestDB}> select * from #18:0
+----+-----+------+----+------------------------------------------------------------------------+
|# |#RID |#CLASS|id |out_MyE |
+----+-----+------+----+------------------------------------------------------------------------+
|0 |#18:0|MyV |1 |[#22:0,#22:1,#22:2,#22:3,#22:4,#22:5,#22:6,#22:7,#22:8,#22:9(size=5001)]|
+----+-----+------+----+------------------------------------------------------------------------+
1 item(s) found. Query executed in 0.001 sec(s).
orientdb {db=TestDB}> load record #18:0
DOCUMENT #class:MyV #rid:#18:0 #version:2
+----+-------+------------------------------------------------------------------------+
|# |NAME |VALUE |
+----+-------+------------------------------------------------------------------------+
|0 |id |1 |
|1 |out_MyE|[#22:0,#22:1,#22:2,#22:3,#22:4,#22:5,#22:6,#22:7,#22:8,#22:9(size=5001)]|
+----+-------+------------------------------------------------------------------------+
OK
This is a common issue caused by a wrong approach to concurrency or transactions.
You're gonna need to troubleshoot the cause and either write fail-safe code or change your graph consistency level
OrientDB | Troubleshooting OConcurrentModificationException
I'm using the Vehicle History database with OrientDb Studio 2.2.8, and I want to project all of the records of the automobile class that are made by Kia.
The schema for the database looks like this:
(Automobile) --isModel--> (Model) --isMake--> (Make)
where Automobile, Model, and Make are vertices and isModel, and isMake are edge types.
I want to use a traverse statement to return an equivalent result set as I get from this command:
Select expand(in('isMake').in('isModel')) from Make where name = "Kia"
whose result is...
+----+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|# |#RID |#CLASS |color |convertib|out_isMod|trailerHi|emissions|safety |out_Purch|VIN |
+----+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
|0 |#17:1441|Automo...|White |true |[#24:1...|false |2016-0...|2014-0...|[#23:5...|840CDC...|
|1 |#17:1576|Automo...|Maroon |true |[#24:1...|false |2010-0...|2004-0...|[#23:5...|E71761...|
|2 |#17:1503|Automo...|Dark Gray|true |[#24:1...|false |2009-0...|2016-1...|[#23:5...|FAEB6F...|
+----+--------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
I tried running this:
Select
from (traverse in from Make while $depth <= 2)
where name = "Kia"
I just get one record returned, and it's not of the Automobile class like I expected it to be. It is from Make.
+----+-------+------+----+-------------------------------------+----------------------------+
|# |#RID |#CLASS|name|in_isMake |out_Sold |
+----+-------+------+----+-------------------------------------+----------------------------+
|0 |#15:612|Make |Kia |[#25:1767,#25:2036,#25:2067,#25:2131]|[#22:5153,#22:5383,#22:5655]|
+----+-------+------+----+-------------------------------------+----------------------------+
Basically, I want to use a Traverse starting from Make to project the three Kia automobiles in the database.
Can you try this?
SELECT FROM (TRAVERSE in()
FROM (SELECT FROM Make where name='Kia'))
WHERE #class='Automobile'
Assume I have following table, plus some data.
create table "common"."log"("id" bigserial primary key,
"level" int not null default 0);
Now I have this select query that would return something like this.
select * from common.log where id=147;
+------+--------+
|id |level |
+------+--------+
|147 |1 |
|147 |2 |
|147 |2 |
|147 |6 |
|147 |90 |
+------+--------+
Now I like to have something like following rather above
+------+---------------+
|id |arr_level |
+------+---------------+
|147 |{1,2,2,6,90} |
+------+---------------+
So is there any implicit select clause/way for doing this? thanks.
pgsql v9.3
You can user array function like this
Select '147' as id,array(select level from common.log where id=147) as arr_level;
Another way, probably more useful if you have more than one id to query:
SELECT id, array_agg(level) FROM common.log GROUP BY id;
See: aggregate functions.
I am struggling, maybe the simplest problem ever. My SQL knowledge pretty much limits me from achieving this. I am trying to build an sql query that should show JobTitle, Note and NoteType. Here is the thing, First job doesn't have any note but we should see it in the results. System notes never and ever should be displayed. An expected result should look like this
Result:
--------------------------------------------
|ID |Title |Note |NoteType |
--------------------------------------------
|1 |FirstJob |NULL |NULL |
|2 |SecondJob |CustomNot1|1 |
|2 |SecondJob |CustomNot2|1 |
|3 |ThirdJob |NULL |NULL |
--------------------------------------------
.
My query (doesn't work, doesn't display third job)
SELECT J.ID, J.Title, N.Note, N.NoteType
FROM JOB J
LEFT OUTER JOIN NOTE N ON N.JobId = J.ID
WHERE N.NoteType IS NULL OR N.NoteType = 1
My Tables:
My JOB Table
----------------------
|ID |Title |
----------------------
|1 |FirstJob |
|2 |SecondJob |
|3 |ThirdJob |
----------------------
My NOTE Table
--------------------------------------------
|ID |JobId |Note |NoteType |
--------------------------------------------
|1 |2 |CustomNot1|1 |
|2 |2 |CustomNot2|1 |
|3 |2 |SystemNot1|2 |
|4 |2 |SystemNot3|2 |
|5 |3 |SystemNot1|2 |
--------------------------------------------
This can't be true together (NoteType can't be NULL as well as 1 at the same time):
WHERE N.NoteType IS NULL AND N.NoteType = 1
You may want to use OR instead to check if NoteType is either NULL or 1.
WHERE N.NoteType IS NULL OR N.NoteType = 1
EDIT: With corrected query, your third job will not be retrieved as JOB_ID is matching but its the row getting filtered out because of the where condition.
Try below as work around to get the third job with null values.
SELECT J.ID, J.Title, N.Note, N.NoteType
FROM JOB J
LEFT OUTER JOIN
( SELECT JOBID NOTE, NOTETYPE FROM NOTE
WHERE N.NoteType IS NULL OR N.NoteType = 1) N
ON N.JobId = J.ID
just exclude the systemNotes and use a sub-select:
select * from job j
left outer join (
select * from note where notetype!=2
) n
on j.id=n.jobid;
if you include the joined table into where then left outer join might work as an inner join.