# Pystardog insert named graph not updating

**URL:** <https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392>\
**Category:** Support\
**Created:** [April 23, 2020, 7:35pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392 "2020-04-23T19:35:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [April 23, 2020, 7:35pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/1 "2020-04-23T19:35:06Z")

</div>

Hi I am a bit new and am getting confused.

I am using pystardog to hit a nonlocal db using virtual graphs. I am connecting to the nonlocal db and can query some results. I am having trouble updating the named graph I created to hold the relevant data. I am using the following options for uploading my ontology.

> admin.new\_database('db', {'edge.properties': True, 'virtual.transparency': True, 'query.all.graphs': True})

Once creating my virtual graphs I perform the following operations:

> conn.begin()  
> conn.add(stardog.content.File('defaultstatement.ttl'), graph\_uri='urn:12345') #this named graph contains an rdf statement.  
> conn.update(sparql)  
> conn.commit()

The update from conn.update(sparql) contains string sparql, which looks something like this:

> INSERT {  
> GRAPH \<urn:12345\> {  
> ?s ?p ?o  
> }}  
> WHERE{  
> ?s a someObjectsAndStuff  
> }  
> however a select query on the named graph does not show the updated values. Any help would be much appreciated!

Thanks,  
Kevin

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [April 23, 2020, 8:25pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/2 "2020-04-23T20:25:05Z")

</div>

Hi Kevin,

What exactly were you expecting the results of the insert query to be? I don’t believe that it’s a valid query since there are no bindings for ?p and ?o but even if it was what I suspect you were trying to do you’d be querying the default graph, which is the union of all graphs including the one you’ve added data to, and inserting it back into the named graph which wouldn’t result in any changes.

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [April 23, 2020, 8:37pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/3 "2020-04-23T20:37:05Z")

</div>

Hi Zachary,

The results I am expecting are the results from a SELECT query on the named graph that I updated with conn.update(sparql). I tried select queries like this :

> SELECT ?s ?p ?o WHERE {GRAPH \<urn:12345\> {?s ?p ?o} }

but they only ever return the defaultstatement.ttl from the named graph.

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [April 23, 2020, 8:43pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/4 "2020-04-23T20:43:18Z")

</div>

Perhaps I am not using the correct methodology for creating a named graph from a nonlocal db.

My thinking:

1. add ontology and create virtual graphs.
2. Create a named graph with conn.add
3. pull a constrained subset of the nonlocal db through virgual graphs and insert it into the named graph
4. prove that this subset of data was put in the named graph by performing the SELECT query of the named graph above

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [April 23, 2020, 8:49pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/5 "2020-04-23T20:49:59Z")

</div>

> [@Kevin\_Vanslette](#):
>
> defaultstatement.ttl

Have you verified adding this file adds the expected data?

Following that, your update must bind all variables in the INSERT which is what Zachary is pointing out.

---

<div class="post-metadata">

**Author:** ![Kevin\_Vanslette](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/kevin_vanslette/32/646_2.png) [@Kevin\_Vanslette](https://community.stardog.com/u/Kevin_Vanslette)\
**Post date:** [April 23, 2020, 8:57pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/6 "2020-04-23T20:57:18Z")

</div>

The default statement does show up as expected:

> \<urn:foo\> a \<urn:bar\>

The INSERT I have looks closer to this in actuality (sorry for the poor example before):

> INSERT {  
> GRAPH urn:12345 {  
> ?s ?p ?o  
> }}  
> WHERE{  
> ?s a someObject
> 
> ...some other constraints and filters...
> 
> ?s ?p ?o  
> }

Does the triple at the end of the where clause sufficiently bind the variables?

---

<div class="post-metadata">

**Author:** ![jess](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/jess/32/10_2.png) [@jess](https://community.stardog.com/u/jess)\
**Post date:** [April 23, 2020, 8:59pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/7 "2020-04-23T20:59:11Z")

</div>

Yes, that looks good. If you have `query.all.graphs` enabled, that should find the data in the `urn:12345` graph (the one you added the file contents to). Does a SELECT work with the same WHERE?

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [April 23, 2020, 9:57pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/8 "2020-04-23T21:57:56Z")

</div>

I see two different formats for BIND in the docs and in the auto-mappings.

Which is correct or do they both work?  
Docs ...  
BIND (template("[http://example.com/acct/{acctNum}](http://example.com/acct/%7BacctNum%7D)") AS ?subject)  
Auto ...  
BIND(template("[http://example.com/acct/acctNum={acctNum}](http://example.com/acct/acctNum=%7BacctNum%7D)") AS ?subject)

Andrea

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [April 23, 2020, 11:20pm UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/9 "2020-04-23T23:20:56Z")

</div>

Your query isn’t going to produce any triples that aren’t already in your named graph unless you were expecting to be adding triples from your virtual graph. Is that what you were expecting?

I don’t think virtual graphs are added to the default graph even if you set the query all graphs option. There is a new feature, auto-virtualization? transparent virtualization? Something like that. I can’t remember the exact name right now. (I’m on my phone). That does do that but you’d have to enable that. I’m not sure if it works for update queries or just select queries. If not you’d have to explicitly add virtual graphs.

---

<div class="post-metadata">

**Author:** ![arwesterinen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/arwesterinen/32/40_2.png) [@arwesterinen](https://community.stardog.com/u/arwesterinen)\
**Post date:** [April 30, 2020, 2:41am UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/10 "2020-04-30T02:41:19Z")

</div>

Zach, We were expecting triples to be added to the named graph from the virtual graph. Virtual Transparency was ON as was the query.all.graphs option.

Jess, You might want to fix the auto-generated mapping output for Studio. It is the one that generated the BIND(template("[[http://example.com/acct/acctNum={acctNum}](http://example.com/acct/acctNum=%7BacctNum%7D)") AS ?subject) clause. This is wrong, since I clearly don't want an = in my IRI. Interestingly enough, the auto-generated mapping in Studio generated BIND clauses to create IRIs without the = as well.

Andrea

---

<div class="post-metadata">

**Author:** ![zachary.whitley](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.stardog.com/zachary.whitley/32/94_2.png) [@zachary.whitley](https://community.stardog.com/u/zachary.whitley)\
**Post date:** [April 30, 2020, 11:12am UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/11 "2020-04-30T11:12:18Z")

</div>

While it lacks a certain aesthetic appeal it comes from the R2RML direct mapping spec [A Direct Mapping of Relational Data to RDF](https://www.w3.org/TR/rdb-direct-mapping/)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/stardog/original/2X/e/ed66b48a616f505106a4acde3c9cee7e6da9bc67.svg) [@system](https://community.stardog.com/u/system)\
**Post date:** [May 14, 2020, 11:12am UTC](https://community.stardog.com/t/pystardog-insert-named-graph-not-updating/2392/12 "2020-05-14T11:12:22Z")

</div>

Closed on May 14, 2020, 11:12am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
