OrientDB: list all indexes - orientdb

For the life of me I cannot figure out how to list all defined indexes within OrientDB. The following is the query syntax if you know the index name:
SELECT FROM INDEX:<index-name> WHERE key = <key>
How can I get a list of the existing index-names?

You can use this query:
select expand(indexes) from #0:2
or:
select expand(indexes) from metadata:indexmanager
Hope it helps.

Related

What is the equivalent of SQL subquery in MongoDB?

Is there a way to combine two finds in MongoDB similar to the SQL subqueries?
What would be the equivalent of something like:
SELECT * FROM TABLE1 WHERE name = (SELECT name FROM TABLE2 WHERE surname = 'Smith');
I need to get an uuid from one collection searching by email and then use it to filter in another. I would like if possible to make it with just one find instead of get the uuid, store it in a variable and then search second time using the variable...
Here are the two that I want combined somehow:
db.getCollection('person').find({email:'perry.goodwin#yahoo.com'}).sort({_id:-1});
db.getCollection('case').find({applicantUuid:'4a17e96c-caf9-4d78-a853-73e190005c63'});

Can't create unique index in postgres, it says "key is duplicate" even when it's not

I created a unique index for a table and got the following error:
SQL error: ERROR: could not create unique index "unique_product" DETAIL: Key (mastercode)=() is duplicated
So i run a query to check for duplicated records and really found some duplicates:
select * from product p where (select count(*) from product pp where pp.mastercode = p.mastercode) > 1
But even after deleting them i could not create the index, it shows the same error and the query to check for duplicates shows nothing.
Looks like it didn't update the indices after deleting the duplicates, or something like that. How can i solve this?
UPDATE
Something i forgot to mention but may be important, i already have an index on the field mastercode, which is a default index (not unique). Don't know if this has something to do.
Check the results from this query:
SELECT mastercode, count(*)
FROM product
GROUP BY mastercode
HAVING count(*) > 1; -- not unique
I believe you have an instance of a null mastercode, and are trying to insert another null mastercode.
Try select * from product where mastercode is null;

IN clause with large list in OpenJpa causing too complex statement

I have to create a named query where I need to group my results by some fields and also using an IN clause to limit my results.
The it looks something like this
SELECT new MyDTO(e.objID) FROM Entity e WHERE e.objId IN (:listOfIDs) GROUP BY e.attr1, e.attr2
I'm using OpenJPA and IBM DB2. In some cases my List of IDs can be very large (>80.000 IDs) and then the generated SQL statement becomes too complex for DB2, because the final generated statement prints out all IDs, like this:
SELECT new MyDTO(e.objID) FROM Entity e WHERE e.objId IN (1,2,3,4,5,6,7,...) GROUP BY e.attr1, e.attr2
Is there any good way to handle this kind of query? A possible Workaround would be to write the IDs in a temporary table and then using the IN clause on this table.
You should put all of the values in a table and rewrite the query as a join. This will not only solve your query problem, it should be more efficient as well.
declare global temporary table ids (
objId int
) with replace on commit preserve rows;
--If this statement is too long, use a couple of insert statements.
insert into session.ids values
(1,2,3,4,....);
select new mydto(e.objID)
from entity e
join session.ids i on
e.objId = i.objId
group by e.attr1, e.attr2;

Combine dynamic columns with select query

I am using a PostgreSQL database. I have one select query:
select userid, name, age from tbluser;
Now there is another table, tblcalculatedtax, which is generated on the fly and their column names are not predefined, the only mapping between that table and this table is userid. I want to get records after joining two tables. How can I get that?
Simpler:
SELECT *
FROM tbluser
JOIN tblcalculatedtax USING (userid)
Details in the fine manual about SELECT.
Your need SQL Joins. Here's a W3Schools tutorial: http://www.w3schools.com/sql/sql_join.asp
To quickly answer your question, though:
SELECT * FROM tbluser
INNER JOIN tblcalculatedtax
ON tbluser.userid=tblcalculatedtext.userid
The * selects all the columns, so you don't need to know their names. Of course, I'm not sure what use a column is to you if you don't know it's name: do you know what data it contains?

Full-text index in PostgreSQL (not 'english' or 'simple)?

I need to store a few hundred thousand HTML documents in a database and be able to search them. But not just for content - I need the searches to match class names, script names and id values (among other things) that might appear as attributes within the HTML tags in the documents. I tried using to_tsvector('english', tableColumn) and to_tsvector('simple', tableColumn) but neither seem to match the contents of attributes in tags. Specifically, I did this:
create index an_index on myTable using gin (to_tsvector('simple',tableColumn))
and then:
select url from myTable where to_tsvector ('simple', tableContent) ## to_tsquery ('myscript.js')
I expected it to retrieve all documents that contained a reference to myscript.js. But it returns no results.
Is it possible to achieve the results I want using the full-text search?
Thanks in advance for your help.
Try instead.
SELECT url FROM myTable WHERE tableColumn ## to_tsquery ('simple','myscript.js')