@@ -133,158 +133,40 @@ SELECT * FROM pg_extension WHERE extname = 'age';
133133
134134== Usage
135135
136- === Create a Graph Database
137-
138136[literal]
139137----
140- -- Load AGE language
141- LOAD 'age';
142-
143- -- Load Cypher functions
144- SET search_path = ag_catalog, "$user", public;
138+ To create a graph, use the create_graph function located in the ag_catalog namespace.
145139
146- -- Create a graph
147140SELECT create_graph('graph_name');
148- ----
149141
150- === Create Vertices
142+ To create a single vertex with label and properties, use the CREATE clause.
151143
152- To create a single vertex with label and properties:
153-
154- [literal]
155- ----
156- SELECT *
144+ SELECT *
157145FROM cypher('graph_name', $$
158146 CREATE (:label {property:"Node A"})
159147$$) as (v agtype);
160- ----
161148
162- [literal]
163- ----
164- SELECT *
149+ SELECT *
165150FROM cypher('graph_name', $$
166151 CREATE (:label {property:"Node B"})
167152$$) as (v agtype);
168- ----
169-
170- === Create Edges
171153
172154To create an edge between two nodes and set its properties:
173155
174- [literal]
175- ----
176- SELECT *
156+ SELECT *
177157FROM cypher('graph_name', $$
178158 MATCH (a:label), (b:label)
179159 WHERE a.property = 'Node A' AND b.property = 'Node B'
180160 CREATE (a)-[e:RELTYPE {property:a.property + '<->' + b.property}]->(b)
181161 RETURN e
182162$$) as (e agtype);
183- ----
184-
185- === Query Graph Data
186163
187164And to query the connected nodes:
188165
189- [literal]
190- ----
191166SELECT * from cypher('graph_name', $$
192- MATCH (V)-[R]-(V2)
193- RETURN V,R,V2
167+ MATCH (V)-[R]-(V2)
168+ RETURN V,R,V2
194169$$) as (V agtype, R agtype, V2 agtype);
195- ----
196170
197- === Basic Query Examples
198-
199- [literal]
200- ----
201- -- Query all vertices
202- SELECT * FROM cypher('graph_name', $$
203- MATCH (V)
204- RETURN V
205- $$) as (V agtype);
206-
207- -- Query vertices with specific label
208- SELECT * FROM cypher('graph_name', $$
209- MATCH (V:label)
210- RETURN V
211- $$) as (V agtype);
212-
213- -- Query vertices with specific property
214- SELECT * FROM cypher('graph_name', $$
215- MATCH (V:label {property: "Node A"})
216- RETURN V
217- $$) as (V agtype);
218-
219- -- Query all edges
220- SELECT * FROM cypher('graph_name', $$
221- MATCH ()-[R]->()
222- RETURN R
223- $$) as (R agtype);
224-
225- -- Query edges by type
226- SELECT * FROM cypher('graph_name', $$
227- MATCH ()-[R:RELTYPE]->()
228- RETURN R
229- $$) as (R agtype);
230171----
231172
232- === Update and Delete
233-
234- [literal]
235- ----
236- -- Update vertex properties
237- SELECT * FROM cypher('graph_name', $$
238- MATCH (V:label {property: "Node A"})
239- SET V.property = "Updated Node A"
240- RETURN V
241- $$) as (V agtype);
242-
243- -- Delete edge
244- SELECT * FROM cypher('graph_name', $$
245- MATCH (a:label {property: "Node A"})-[r:RELTYPE]->(b:label {property: "Node B"})
246- DELETE r
247- $$) as (r agtype);
248-
249- -- Delete vertex (must delete related edges first)
250- SELECT * FROM cypher('graph_name', $$
251- MATCH (V:label {property: "Node B"})
252- DETACH DELETE V
253- $$) as (V agtype);
254- ----
255-
256- === Combining with SQL
257-
258- [literal]
259- ----
260- -- Use graph query results in relational queries
261- SELECT * FROM cypher('graph_name', $$
262- MATCH (V:label)
263- RETURN V.property AS name
264- $$) as (name text)
265- WHERE name IS NOT NULL;
266-
267- -- Count vertices
268- SELECT count(*) FROM cypher('graph_name', $$
269- MATCH (V)
270- RETURN V
271- $$) as (V agtype);
272- ----
273-
274- == Management Commands
275-
276- [literal]
277- ----
278- -- List all graphs
279- SELECT * FROM ag_graph;
280-
281- -- Delete graph (deletes all related vertices and edges)
282- SELECT drop_graph('graph_name', true);
283-
284- -- View graph statistics
285- SELECT
286- graph_name,
287- (SELECT count(*) FROM ag_vertex WHERE graph_id = ag_graph.graph_id) AS vertex_count,
288- (SELECT count(*) FROM ag_edge WHERE graph_id = ag_graph.graph_id) AS edge_count
289- FROM ag_graph;
290- ----
0 commit comments