Home > Blog > [Q&A Friday] SELECT clause in Nuxeo NXQL queries

[Q&A Friday] SELECT clause in Nuxeo NXQL queries

Hello Everyone! Today we have a question from Franck. He’s asking why he cannot do query with a specific select clause like this :

[bash]
Administrator@127.0.0.1:/> query "select dc:title from myDocumentType"
Administrator@127.0.0.1:/>`
[/bash]

while this is working fine:

[bash]
Administrator@127.0.0.1:/> query "select * from myDocumentType"
/default-domain/workspaces/Library/sections/North America
[/bash]

SELECT clause in NXQL queries

SELECT clause in NXQL queries

Frank is actually running those queries from Nuxeo Shell. The query command uses the Document.Query operation which itself uses CoreSession#query. This method will only return a DocumentModelList so you cannot use a specific select clause in your query. And this makes sense, because with Content Automation, you usually manipulate Documents.

So when can you use a specific select clause? You have to use CoreSession#queryAndFetch. This will return an IterableQueryResult. If you still want to do your query from the shell, a quick and easy way to do it is to use a Groovy script like this:

[groovy]
iterableQueryResult = Session.queryAndFetch("SELECT dc:title,ecm:uuid FROM Document WHERE dc:title = ‘Workspace’", "NXQL");
out = "";
while(iterableQueryResult.hasNext()){
out += iterableQueryResult.next().toString() + "n";
}
// don’t forget to close it!
iterableQueryResult.close();
return out;
[/groovy]

To call it you have to use the script command and give it the path of your Groovy script:

[bash]
Administrator@localhost:/> script /home/ldoguin/test.groovy
{ecm:uuid=168458db-47fc-4c34-be50-bdc6f4dbcb56, dc:title=Workspace}
[/bash]

If you want to know more about Nuxeo’s NXQL, take a look at the documentation.

Cheers!

Nuxeo Document Management
Document
Management
with the
Nuxeo Platform Watch the webinar >
img
img
img
img
  • Franck

    Your reply makes perfect sense, thanks. I am not convinced that the improvement wouldn’t be valuable though, the Automation API seems to be the preferred remote interface technology and remote calls is precisely when you want to be able to precisely control the amount of data you retrieve based on the specific view or task at hand…
    Nothing that can’t be dealt with with a custom operation though, I will take that approach.

  • Franck

    Your reply makes perfect sense, thanks. I am not convinced that the improvement wouldn’t be valuable though, the Automation API seems to be the preferred remote interface technology and remote calls is precisely when you want to be able to precisely control the amount of data you retrieve based on the specific view or task at hand…
    Nothing that can’t be dealt with with a custom operation though, I will take that approach.

  • Williams Rivas

    Hi I am using this code but the DocumentModel does not have the Blob file:

    String sql = “SELECT * FROM File”;

    DocumentModelList dml = documentManager. query(sql, 1);

  • Williams Rivas

    Hi I am using this code but the DocumentModel does not have the Blob file:

    String sql = “SELECT * FROM File”;

    DocumentModelList dml = documentManager. query(sql, 1);

  • http://www.cuclapita.com explanation

    I simply want to mention I’m newbie to blogging and really loved you’re web blog. Most likely I’m planning to bookmark your website . You amazingly come with exceptional articles. Thanks a lot for revealing your website.

  • http://www.hotcore.info Royal Dowson

    Might be almost unthinkable to come across well-qualified users on this theme, although you look like you are familiar with the things you’re covering! Bless You

  • http://www.forestryblog.org Arcelia Luccous

    You’ll find it mostly close to impossible to find well-qualified americans on this theme, then again you come across as like you realize those things you’re writing about! Thanks

  • http://www.cumshotsurprisetgp.com additional resources
  • http://about.me/andsbzasj cialis bez recepty

    You have made some really good points there. I looked on the net for more information about the issue and found most individuals will go along with your views on this web site.

  • http://www.dans-porn-links.com check over here
  • http://www.albumsexo.com/15/follando-por-el-culo-a-una-rubia-tetona/ great article
  • http://www.flt-staging.com Magaly Bulgrin

    You’ll find it nearly unattainable to come across well-advised visitors on this niche, fortunately you seem like you be aware of which you’re revealing! Many Thanks

  • http://www.samsungxoa.com Sherill Palmieri

    It can be almost not possible to encounter well-informed men or women on this issue, regrettably you come across as like you are familiar with what you’re indicating! Thanks A Lot

  • http://www.plumppornstars.com/25/disfrutando-de-follar-a-una-pija-tetona/ original site

    I simply want to tell you that I’m beginner to blogging and site-building and certainly loved you’re page. More than likely I’m likely to bookmark your site . You definitely have very good posts. Bless you for sharing with us your web-site.

  • http://jjj Gerardo Awe

    Opinie wyszukane na http://pozyczka-ogloszenia.pl

  • Pingback: Google()

  • Pingback: URL()