You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@age.apache.org by "hammadsaleemm (via GitHub)" <gi...@apache.org> on 2023/05/20 06:40:13 UTC

[GitHub] [age] hammadsaleemm opened a new issue, #939: Retaining vertices after deleting edges using constraints

hammadsaleemm opened a new issue, #939:
URL: https://github.com/apache/age/issues/939

   I have a graph database where I want to delete specific edges while retaining the corresponding vertices. Currently, I'm using constraints to ensure data integrity and maintain referential integrity between the vertices and edges.
   
   My database schema includes two tables: vertices and edges. The vertices table represents the vertices in the graph, and the edges table represents the edges connecting those vertices. I'm using foreign key constraints between the edges table and the vertices table.
   
   The issue I'm facing is that when I delete an edge, the associated vertices are also deleted due to the cascading behavior defined in the constraints. However, I would like to retain the vertices even after deleting the edges.
   
   Is there a way to modify the constraints or define new constraints in such a way that the vertices are not deleted when deleting the edges? I want to ensure that the vertices remain in the database, even if they are not connected to any edges.
   
   Any guidance, suggestions, or code examples would be highly appreciated. Thank you!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] waleedahmed0001 commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "waleedahmed0001 (via GitHub)" <gi...@apache.org>.
waleedahmed0001 commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1555874624

   To delete an edge, use the match clause to find your edges, then add the variable to the DELETE.
   
   ```
   SELECT * 
   FROM cypher('graph_name', $$
   	MATCH (n {name: 'Andres'})-[r:KNOWS]->()
   	DELETE r
   $$) as (v agtype);
   ```
   
   The above query will just delete the relationship or edge while the vertex will remain there.
   
   But we use the detach delete command to delete the edges first associated with a vertex and then the vertex would be deleted.
   ```
   SELECT * 
   FROM cypher('graph_name', $$
   	MATCH (v:Useless)
   	 DETACH DELETE v
   $$) as (v agtype);
   ```
   
   So, there is no chance that vertex will be deleted directly by deleting the edges because vertex cannot be deleted if it has vertices attached with it using the delete command only.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] AhmedMo0 commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "AhmedMo0 (via GitHub)" <gi...@apache.org>.
AhmedMo0 commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1565539826

   In Age deleting an edge doesn't require deleting its vertices to know more about DELETE clause refer to the [documentation](https://age.apache.org/age-manual/v0.6.0/clauses/delete.html) 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] mahinash26 commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "mahinash26 (via GitHub)" <gi...@apache.org>.
mahinash26 commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1590729924

   In Apache AGE, the corresponding vertices are not deleted when an edge is removed from a graph. The vertices and edges are like considered independent entities within the graph. Deleting an edge only impacts the presence of that specific edge, while the associated vertices remain unaffected.
   
   `SELECT * FROM cypher('test', $$
   MATCH (u)-[e:EDGE_LABEL]->(v)
   WHERE e.property = 'value'
   DELETE e  
   RETURN e
   $$) AS (result agtype);
   `
   So in this code, 'EDGE_LABEL' should be substituted with the label of the edges you intend to delete. Additionally, replace 'property' with the specific property name you want to filter and 'value' with the desired value for selecting the edges to be removed. By customizing these query parts, you should be able to filter as well as delete the targeted edges from your graph while retaining the associated vertices.
   
   I hope this helps.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] M4rcxs commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "M4rcxs (via GitHub)" <gi...@apache.org>.
M4rcxs commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1564735611

   deleting an edge doesn't inherently result in the automatic removal of the vertices linked to it. Can you share a piece of your code so we can discuss it efficiently?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] safi50 commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "safi50 (via GitHub)" <gi...@apache.org>.
safi50 commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1555882537

   Refer to this [Stack Overflow Question](https://stackoverflow.com/questions/76233940/age-graph-delete-constraints/76238638#76238638) about how `DELETE` works and its constraints. 
   
   Additionally, more information is given in the [Apache AGE documentation](https://age.apache.org/age-manual/v0.6.0/clauses/delete.html). By default, deleting edges does not delete corresponding vertices. However, that too can be done via `DETACH DELETE`. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] titoausten commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "titoausten (via GitHub)" <gi...@apache.org>.
titoausten commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1555864520

   @Zainab-Saad and @TalhaMunir-JD already stated what happens when you delete an edge. Please share the queriesbor a piece of thw code as this would help understand why the vertices are also deleted and suggest solutions.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] Zainab-Saad commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "Zainab-Saad (via GitHub)" <gi...@apache.org>.
Zainab-Saad commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1555842153

   In AGE, deleting an edge would not delete the corresponding vertices. For example, the query:
   ```SELECT * FROM cypher('test', $$
   MATCH (u)-[e]->(v) DELETE e  
   RETURN e
   $$) AS (result agtype);
   ```
   
   This deletes all the edges while retaining the corresponding vertices. 
   
   Moreover, as per your question, could you provide supporting queries so that I can get an idea what is being done. 
   PS: It is not recommended to perform any DDL commands on the table in which the graph data is stored. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] abdulmanann commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "abdulmanann (via GitHub)" <gi...@apache.org>.
abdulmanann commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1568336199

   It seems like there might be some misunderstanding about how AGE works with edges and vertices. When you delete an edge, it should not delete the associated vertices. This is one of the fundamental principles of graph databases: vertices and edges are independent entities.
   
   From your description, it appears you are trying to handle the vertices and edges as relational tables with foreign key constraints. However, this isn't necessary with Apache AGE as it already manages these relationships internally within its graph model.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] humzakt commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "humzakt (via GitHub)" <gi...@apache.org>.
humzakt commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1570674997

   t seems like the foreign key constraints on your edges table are set to CASCADE DELETE. This means that when an edge is deleted, the corresponding vertices get deleted as well.
   
   What you need to do is to change these constraints so that the deletion of an edge doesn't lead to the deletion of its corresponding vertices.
   
   Here's how you can alter your foreign key constraint:
   
   First, you need to drop the existing constraints. Here's how you might do it (replace fk_edge_vertex1 and fk_edge_vertex2 with your actual constraint names, and edges with your actual table name):
   ```
   ALTER TABLE edges DROP CONSTRAINT fk_edge_vertex1;
   ALTER TABLE edges DROP CONSTRAINT fk_edge_vertex2;
   ```
   
   After dropping the existing constraints, you can add new foreign key constraints that don't cascade on delete. Here's how:
   ```
   ALTER TABLE edges 
   ADD CONSTRAINT fk_edge_vertex1 
   FOREIGN KEY (vertex1_id) REFERENCES vertices(id);
   
   ALTER TABLE edges 
   ADD CONSTRAINT fk_edge_vertex2 
   FOREIGN KEY (vertex2_id) REFERENCES vertices(id);
   ```
   
   In these statements, vertex1_id and vertex2_id are the foreign keys in the edges table, and id is the primary key in the vertices table.
   
   This will ensure that when an edge is deleted, the corresponding vertices will not be deleted.
   
   Please note: always be cautious when altering table structures in a production environment. It's a good practice to backup your database before making such changes.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] RahimullahShaheen commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "RahimullahShaheen (via GitHub)" <gi...@apache.org>.
RahimullahShaheen commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1561285317

   Basically in graph database deleting an edge does not automatically delete the vertices attached to it. because the vertices are separate entities in the graph. 
   In your case it might be possible that the foreign key specified  between the edges and vertices table is leading to the deletion of vertices when an edge is deleted. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] TalhaMunir-JD commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "TalhaMunir-JD (via GitHub)" <gi...@apache.org>.
TalhaMunir-JD commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1555860556

   Mostly when you delete an edge in a graph database the associated vertices will not be deleted from the database. Deleting a specific edge wont necessarily delete your vertices. This is one of the advantages of graph databases.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [age] dukeofhazardz commented on issue #939: Retaining vertices after deleting edges using constraints

Posted by "dukeofhazardz (via GitHub)" <gi...@apache.org>.
dukeofhazardz commented on issue #939:
URL: https://github.com/apache/age/issues/939#issuecomment-1563547525

   If you want more clarity on deleting edges without affecting vertices, I recommend checking out this blog post [delete and detach delete](https://dev.to/dukeofhazardz/how-to-perform-delete-and-detach-delete-in-apache-age-4m1b) that discusses strategies for achieving this in a graph database. It provides detailed explanations and examples that can help you understand the process better. Alternatively, if you can share specific code snippets or more information about your database schema and constraints, it would go a long way to help understand the dynamics of your problem.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@age.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org