how to store a result in a database?
Wednesday, 19 February 2020 · 4 messages · last reply 20 Feb 2020
MH
Quoted text · thufir · 15 lines
Am 19.02.2020 um 14:36 schrieb thufir: > While I can certainly output the result to a file, and then add to a > database, how would I actually send the result directly to a database? > > xquery version "3.0"; > > <xml> > { > for $line in db:open("people.json")//text() > return > if (matches($line, "[0-9]")) > then <data>{$line}</data> > else <record>{$line}</record> > } > </xml>
See http://docs.basex.org/wiki/Database_Module#db:add, you seem to want
db:add("people.all",
<xml>
{
for $line in db:open("people.json")//text()
return
if (matches($line, "[0-9]"))
then <data>{$line}</data>
else <record>{$line}</record>
}
</xml>)
that is, you simply want to pass your query result as the second argument to the
db:add function.Quoted text · thufir · 32 lines
> > Currently I'm running it like so: > > thufir@dur:~/flwor/people.json$ > thufir@dur:~/flwor/people.json$ basex all.xq > all.xml > thufir@dur:~/flwor/people.json$ > thufir@dur:~/flwor/people.json$ basex > BaseX 9.0.1 [Standalone] > Try 'help' to get more information. > > > > create database people.all > Database 'people.all' created in 234.74 ms. > > > > set parser xml > PARSER: xml > > > > add all.xml > Resource(s) added in 377.43 ms. > > > > exit > Have fun. > thufir@dur:~/flwor/people.json$ > > > but that's a bit cumbersome. > > > > > thanks, > > Thufir
T
thufir19 Feb 2020 15:36 #
While I can certainly output the result to a file, and then add to a database, how would I actually send the result directly to a database?
xquery version "3.0";
<xml>
{
for $line in db:open("people.json")//text()
return
if (matches($line, "[0-9]"))
then <data>{$line}</data>
else <record>{$line}</record>
}
</xml>Currently I'm running it like so:
thufir@dur:~/flwor/people.json$
thufir@dur:~/flwor/people.json$ basex all.xq > all.xml
thufir@dur:~/flwor/people.json$
thufir@dur:~/flwor/people.json$ basex
BaseX 9.0.1 [Standalone]
Try 'help' to get more information.
Quoted text · 2 lines
> > create database people.all
Database 'people.all' created in 234.74 ms.
Quoted text · 2 lines
> > set parser xml
PARSER: xmlQuoted text · 2 lines
> > add all.xml
Resource(s) added in 377.43 ms.
Quoted text · 2 lines
> > exit
Have fun.
thufir@dur:~/flwor/people.json$
but that's a bit cumbersome.
thanks,
Thufir
CG
Hi Thufir,
Quoted text · thufir · 3 lines
> I see what you mean by passing the query result as the second argument > to the db:add function, but am getting: > [XPST0003] Expecting function argument.
Please take a few times to read our docs and try out the examples; I’m sure you’ll find out soon what’s the correct syntax.
Best,
Christian
Quoted text · thufir · 95 lines
On Thu, Feb 20, 2020 at 12:14 PM thufir <hawat.thufir at gmail.com> wrote: > > > > A syntax problem? > > xquery version "3.0"; > > db:add("foo.clean.xml", > > <xml> > { > for $x in db:open("foo.txt")/text/line > return $x > } > </xml> > > > > > > > > On 2020-02-19 6:08 a.m., Martin Honnen wrote: > > Am 19.02.2020 um 14:36 schrieb thufir: > >> While I can certainly output the result to a file, and then add to a > >> database, how would I actually send the result directly to a database? > >> > >> xquery version "3.0"; > >> > >> <xml> > >> { > >> for $line in db:open("people.json")//text() > >> return > >> if (matches($line, "[0-9]")) > >> then <data>{$line}</data> > >> else <record>{$line}</record> > >> } > >> </xml> > > > > > > See http://docs.basex.org/wiki/Database_Module#db:add, you seem to want > > > > db:add("people.all", > > > > <xml> > > { > > for $line in db:open("people.json")//text() > > return > > if (matches($line, "[0-9]")) > > then <data>{$line}</data> > > else <record>{$line}</record> > > } > > </xml> > > > > ) > > > > > > that is, you simply want to pass your query result as the second > > argument to the db:add function. > > > >> > >> Currently I'm running it like so: > >> > >> thufir@dur:~/flwor/people.json$ > >> thufir@dur:~/flwor/people.json$ basex all.xq > all.xml > >> thufir@dur:~/flwor/people.json$ > >> thufir@dur:~/flwor/people.json$ basex > >> BaseX 9.0.1 [Standalone] > >> Try 'help' to get more information. > >> > > >> > create database people.all > >> Database 'people.all' created in 234.74 ms. > >> > > >> > set parser xml > >> PARSER: xml > >> > > >> > add all.xml > >> Resource(s) added in 377.43 ms. > >> > > >> > exit > >> Have fun. > >> thufir@dur:~/flwor/people.json$ > >> > >> > >> but that's a bit cumbersome. > >> > >> > >> > >> > >> thanks, > >> > >> Thufir > > > >
T
I see what you mean by passing the query result as the second argument to the
db:add function, but am getting:
[XPST0003] Expecting function argument.
A syntax problem?
xquery version "3.0";db:add("foo.clean.xml",
<xml>
{
for $x in db:open("foo.txt")/text/line
return $x
}
</xml>Quoted text · Martin Honnen · 72 lines
On 2020-02-19 6:08 a.m., Martin Honnen wrote: > Am 19.02.2020 um 14:36 schrieb thufir: >> While I can certainly output the result to a file, and then add to a >> database, how would I actually send the result directly to a database? >> >> xquery version "3.0"; >> >> <xml> >> { >> for $line in db:open("people.json")//text() >> return >> if (matches($line, "[0-9]")) >> then <data>{$line}</data> >> else <record>{$line}</record> >> } >> </xml> > > > See http://docs.basex.org/wiki/Database_Module#db:add, you seem to want > > db:add("people.all", > > <xml> > { > for $line in db:open("people.json")//text() > return > if (matches($line, "[0-9]")) > then <data>{$line}</data> > else <record>{$line}</record> > } > </xml> > > ) > > > that is, you simply want to pass your query result as the second > argument to the db:add function. > >> >> Currently I'm running it like so: >> >> thufir@dur:~/flwor/people.json$ >> thufir@dur:~/flwor/people.json$ basex all.xq > all.xml >> thufir@dur:~/flwor/people.json$ >> thufir@dur:~/flwor/people.json$ basex >> BaseX 9.0.1 [Standalone] >> Try 'help' to get more information. >> > >> > create database people.all >> Database 'people.all' created in 234.74 ms. >> > >> > set parser xml >> PARSER: xml >> > >> > add all.xml >> Resource(s) added in 377.43 ms. >> > >> > exit >> Have fun. >> thufir@dur:~/flwor/people.json$ >> >> >> but that's a bit cumbersome. >> >> >> >> >> thanks, >> >> Thufir > >
Written for BaseX 9.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery