I would like to be able to create a database and populate it with the result of a query done on multiple databases.
How do I do that?
Jonathan
Hello Jonathan,
There are very many answers to your question and you should be more clear in what you want (how is the old database organized? how do you want to organize the new database? what items do you want to carry over from the old to the new db? etc). Depending on this, it might be good to first create a copy of the old database and remove unnecessary things from it and augment it with populating from the other databases.
For creating and updating databases, the core thing to know (in my humble opinion) is the concept of the Pending Update List [1]. This means that a query does not make any updates on a db while the query is running, it instead creates a list of updates and these updates are carried out *after* the query ran *successfully*. This gives a lot of opportunities for optimisations behind the scenes.
Anyway, this implies that the database needs to be existing before you run the query for populating it. This means you need to do it in two runs, first create the database:
db:create($name-of-the-new-db)
after that you need to run the query or queries that populates it, e.g something like:
let $new-item := <new-item> { for $old-item in db:open($old-db)/with/some/items (: populate new-item with only 'this' and 'that' attributes from the old items :) return ($old-item/@this, $old-item/@that) } </new-item> return db:add($name-of-the-new-db, $new-item, $path-to-new-item)
As your question is very open, I would say it is the organisation of the $path-to-new-item that gives most room for answers. Do you want to have everything in one file or many files?
Best rergards, Kristian Kankainen
[1]: https://docs.basex.org/wiki/XQuery_Update#Pending_Update_List
On 22. Jul 2021, at 16:33, Jonathan Robie jonathan.robie@gmail.com wrote:
I would like to be able to create a database and populate it with the result of a query done on multiple databases.
How do I do that?
Jonathan
…one more note: It’s also possible to pass on initial input to db:create:
let $cities := element cities { for $i in 0 to 9 return db:open('countries' || $i)//city } return db:create('db', $cities, 'cities.xml')
Best, Christian
On Fri, Jul 23, 2021 at 7:53 AM Kristian Kankainen kristian@keeleleek.ee wrote:
Hello Jonathan,
There are very many answers to your question and you should be more clear in what you want (how is the old database organized? how do you want to organize the new database? what items do you want to carry over from the old to the new db? etc). Depending on this, it might be good to first create a copy of the old database and remove unnecessary things from it and augment it with populating from the other databases.
For creating and updating databases, the core thing to know (in my humble opinion) is the concept of the Pending Update List [1]. This means that a query does not make any updates on a db while the query is running, it instead creates a list of updates and these updates are carried out *after* the query ran *successfully*. This gives a lot of opportunities for optimisations behind the scenes.
Anyway, this implies that the database needs to be existing before you run the query for populating it. This means you need to do it in two runs, first create the database:
db:create($name-of-the-new-db)
after that you need to run the query or queries that populates it, e.g something like:
let $new-item :=
<new-item> { for $old-item in db:open($old-db)/with/some/items (: populate new-item with only 'this' and 'that' attributes from the old items :) return ($old-item/@this, $old-item/@that) } </new-item> return db:add($name-of-the-new-db, $new-item, $path-to-new-item)
As your question is very open, I would say it is the organisation of the $path-to-new-item that gives most room for answers. Do you want to have everything in one file or many files?
Best rergards, Kristian Kankainen
On 22. Jul 2021, at 16:33, Jonathan Robie jonathan.robie@gmail.com wrote:
I would like to be able to create a database and populate it with the result of a query done on multiple databases.
How do I do that?
Jonathan
Thanks Kristian and Christian,
Very helpful answers. As usual.
Jonathan
On Fri, Jul 23, 2021 at 4:30 AM Christian Grün christian.gruen@gmail.com wrote:
…one more note: It’s also possible to pass on initial input to db:create:
let $cities := element cities { for $i in 0 to 9 return db:open('countries' || $i)//city } return db:create('db', $cities, 'cities.xml')
Best, Christian
On Fri, Jul 23, 2021 at 7:53 AM Kristian Kankainen kristian@keeleleek.ee wrote:
Hello Jonathan,
There are very many answers to your question and you should be more
clear in what you want (how is the old database organized? how do you want to organize the new database? what items do you want to carry over from the old to the new db? etc). Depending on this, it might be good to first create a copy of the old database and remove unnecessary things from it and augment it with populating from the other databases.
For creating and updating databases, the core thing to know (in my
humble opinion) is the concept of the Pending Update List [1]. This means that a query does not make any updates on a db while the query is running, it instead creates a list of updates and these updates are carried out *after* the query ran *successfully*. This gives a lot of opportunities for optimisations behind the scenes.
Anyway, this implies that the database needs to be existing before you
run the query for populating it. This means you need to do it in two runs, first create the database:
db:create($name-of-the-new-db)
after that you need to run the query or queries that populates it, e.g
something like:
let $new-item :=
<new-item> { for $old-item in db:open($old-db)/with/some/items (: populate new-item with only 'this' and 'that' attributes from the
old items :)
return ($old-item/@this, $old-item/@that)
}
</new-item> return db:add($name-of-the-new-db, $new-item, $path-to-new-item)
As your question is very open, I would say it is the organisation of the
$path-to-new-item that gives most room for answers. Do you want to have everything in one file or many files?
Best rergards, Kristian Kankainen
On 22. Jul 2021, at 16:33, Jonathan Robie jonathan.robie@gmail.com
wrote:
I would like to be able to create a database and populate it with the
result of a query done on multiple databases.
How do I do that?
Jonathan
basex-talk@mailman.uni-konstanz.de