You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@age.apache.org by jo...@apache.org on 2021/04/01 01:14:13 UTC

[incubator-age] branch master updated: Make internal updating data structures ExtensibleNodes

This is an automated email from the ASF dual-hosted git repository.

joshinnis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-age.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ba89b0  Make internal updating data structures ExtensibleNodes
7ba89b0 is described below

commit 7ba89b01c8e249ae2df77854698fc87eec90dabb
Author: Josh Innis <Jo...@gmail.com>
AuthorDate: Wed Mar 31 18:10:16 2021 -0700

    Make internal updating data structures ExtensibleNodes
    
    Added copy, serialization and deserialization functions
    for the CREATE, SET, REMOVE and DELETE data structures.
    
    This makes these clauses compatiple with the Prepared
    Statements and pl/pgsql functions.
---
 Makefile                             |   4 +-
 regress/expected/cypher_create.out   |  60 +++++-
 regress/expected/cypher_delete.out   |  59 +++++-
 regress/expected/cypher_remove.out   | 123 ++++++++++++
 regress/expected/cypher_set.out      | 103 ++++++++++
 regress/sql/cypher_create.sql        |  32 ++-
 regress/sql/cypher_delete.sql        |  31 ++-
 regress/sql/cypher_remove.sql        |  24 +++
 regress/sql/cypher_set.sql           |  27 ++-
 src/backend/executor/cypher_create.c |  10 +-
 src/backend/executor/cypher_delete.c |  10 +-
 src/backend/executor/cypher_set.c    |  10 +-
 src/backend/nodes/ag_nodes.c         |  55 +++--
 src/backend/nodes/cypher_copyfuncs.c | 162 +++++++++++++++
 src/backend/nodes/cypher_outfuncs.c  | 380 +++++++++++++++++++++++++++++++++++
 src/backend/nodes/cypher_readfuncs.c | 277 +++++++++++++++++++++++++
 src/backend/nodes/outfuncs.c         | 251 -----------------------
 src/backend/optimizer/cypher_paths.c |  15 +-
 src/backend/parser/cypher_clause.c   |  73 +++++--
 src/include/nodes/ag_nodes.h         |  12 +-
 src/include/nodes/cypher_copyfuncs.h |  50 +++++
 src/include/nodes/cypher_nodes.h     |  71 +++----
 src/include/nodes/cypher_outfuncs.h  |  79 ++++++++
 src/include/nodes/cypher_readfuncs.h |  55 +++++
 24 files changed, 1620 insertions(+), 353 deletions(-)

diff --git a/Makefile b/Makefile
index 245f0f7..5be9080 100644
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,9 @@ OBJS = src/backend/age.o \
        src/backend/executor/cypher_set.o \
        src/backend/executor/cypher_utils.o \
        src/backend/nodes/ag_nodes.o \
-       src/backend/nodes/outfuncs.o \
+       src/backend/nodes/cypher_copyfuncs.o \
+       src/backend/nodes/cypher_outfuncs.o \
+       src/backend/nodes/cypher_readfuncs.o \
        src/backend/optimizer/cypher_createplan.o \
        src/backend/optimizer/cypher_pathnode.o \
        src/backend/optimizer/cypher_paths.o \
diff --git a/regress/expected/cypher_create.out b/regress/expected/cypher_create.out
index 18d2202..c3ff157 100644
--- a/regress/expected/cypher_create.out
+++ b/regress/expected/cypher_create.out
@@ -440,6 +440,55 @@ SELECT * FROM cypher('cypher_create', $$MATCH (n) RETURN n$$) AS (n agtype);
  {"id": 1970324836974595, "label": "n_other_node", "properties": {}}::vertex
 (46 rows)
 
+-- prepared statements
+PREPARE p_1 AS SELECT * FROM cypher('cypher_create', $$CREATE (v:new_vertex {key: 'value'}) RETURN v$$) AS (a agtype);
+EXECUTE p_1;
+                                            a                                            
+-----------------------------------------------------------------------------------------
+ {"id": 2533274790395905, "label": "new_vertex", "properties": {"key": "value"}}::vertex
+(1 row)
+
+EXECUTE p_1;
+                                            a                                            
+-----------------------------------------------------------------------------------------
+ {"id": 2533274790395906, "label": "new_vertex", "properties": {"key": "value"}}::vertex
+(1 row)
+
+PREPARE p_2 AS SELECT * FROM cypher('cypher_create', $$CREATE (v:new_vertex {key: $var_name}) RETURN v$$, $1) AS (a agtype);
+EXECUTE p_2('{"var_name": "Hello Prepared Statements"}');
+                                                      a                                                      
+-------------------------------------------------------------------------------------------------------------
+ {"id": 2533274790395907, "label": "new_vertex", "properties": {"key": "Hello Prepared Statements"}}::vertex
+(1 row)
+
+EXECUTE p_2('{"var_name": "Hello Prepared Statements 2"}');
+                                                       a                                                       
+---------------------------------------------------------------------------------------------------------------
+ {"id": 2533274790395908, "label": "new_vertex", "properties": {"key": "Hello Prepared Statements 2"}}::vertex
+(1 row)
+
+-- pl/pgsql
+CREATE FUNCTION create_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_create', $$CREATE (v:new_vertex {key: 'value'}) RETURN v$$) AS (a agtype);
+END
+$BODY$;
+SELECT create_test();
+                                       create_test                                       
+-----------------------------------------------------------------------------------------
+ {"id": 2533274790395909, "label": "new_vertex", "properties": {"key": "value"}}::vertex
+(1 row)
+
+SELECT create_test();
+                                       create_test                                       
+-----------------------------------------------------------------------------------------
+ {"id": 2533274790395910, "label": "new_vertex", "properties": {"key": "value"}}::vertex
+(1 row)
+
 --
 -- Errors
 --
@@ -502,9 +551,12 @@ ERROR:  column definition list for CREATE clause must contain a single agtype at
 LINE 1: SELECT * FROM cypher('cypher_create', $$CREATE ()$$) AS (a a...
                       ^
 HINT:  ... cypher($$ ... CREATE ... $$) AS t(c agtype) ...
--- intial and last vertex point to the middle vertex
+--
+-- Clean up
+--
+DROP FUNCTION create_test;
 SELECT drop_graph('cypher_create', true);
-NOTICE:  drop cascades to 8 other objects
+NOTICE:  drop cascades to 9 other objects
 DETAIL:  drop cascades to table cypher_create._ag_label_vertex
 drop cascades to table cypher_create._ag_label_edge
 drop cascades to table cypher_create.v
@@ -513,9 +565,13 @@ drop cascades to table cypher_create.n_var
 drop cascades to table cypher_create.e_var
 drop cascades to table cypher_create.n_other_node
 drop cascades to table cypher_create.b_var
+drop cascades to table cypher_create.new_vertex
 NOTICE:  graph "cypher_create" has been dropped
  drop_graph 
 ------------
  
 (1 row)
 
+--
+-- End
+--
diff --git a/regress/expected/cypher_delete.out b/regress/expected/cypher_delete.out
index 8d25912..0b0980b 100644
--- a/regress/expected/cypher_delete.out
+++ b/regress/expected/cypher_delete.out
@@ -429,7 +429,7 @@ SELECT * FROM cypher('cypher_delete', $$CREATE (n:v)$$) AS (a agtype);
 SELECT * FROM cypher('cypher_delete', $$MATCH (n) DELETE n CREATE (n)-[:e]->(:v) RETURN n$$) AS (a agtype);
 ERROR:  vertex assigned to variable n was deleted
 --Cleanup
-SELECT * FROM cypher('cypher_delete', $$MATCH(n) RETURN n$$) AS (a agtype);
+SELECT * FROM cypher('cypher_delete', $$MATCH(n) DELETE n RETURN n$$) AS (a agtype);
                                 a                                
 -----------------------------------------------------------------
  {"id": 844424930132007, "label": "v", "properties": {}}::vertex
@@ -440,9 +440,66 @@ SELECT * FROM cypher('cypher_delete', $$MATCH (n) DELETE m RETURN n$$) AS (a agt
 ERROR:  undefined reference to variable m in DELETE clause
 LINE 1: ...* FROM cypher('cypher_delete', $$MATCH (n) DELETE m RETURN n...
                                                              ^
+--Test 21 Prepared Statements
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+PREPARE d AS SELECT * FROM cypher('cypher_delete', $$MATCH (v) DELETE (v) RETURN v$$) AS (a agtype);
+EXECUTE d;
+                                a                                
+-----------------------------------------------------------------
+ {"id": 844424930132008, "label": "v", "properties": {}}::vertex
+(1 row)
+
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+EXECUTE d;
+                                a                                
+-----------------------------------------------------------------
+ {"id": 844424930132009, "label": "v", "properties": {}}::vertex
+(1 row)
+
+--Test 22 pl/pgsql Functions
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+CREATE FUNCTION delete_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_delete', $$MATCH (v) DELETE (v) RETURN v$$) AS (a agtype);
+END
+$BODY$;
+SELECT delete_test();
+                           delete_test                           
+-----------------------------------------------------------------
+ {"id": 844424930132010, "label": "v", "properties": {}}::vertex
+(1 row)
+
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+SELECT delete_test();
+                           delete_test                           
+-----------------------------------------------------------------
+ {"id": 844424930132011, "label": "v", "properties": {}}::vertex
+(1 row)
+
 --
 -- Clean up
 --
+DROP FUNCTION delete_test;
 SELECT drop_graph('cypher_delete', true);
 NOTICE:  drop cascades to 4 other objects
 DETAIL:  drop cascades to table cypher_delete._ag_label_vertex
diff --git a/regress/expected/cypher_remove.out b/regress/expected/cypher_remove.out
index cb299a7..8d2ddb6 100644
--- a/regress/expected/cypher_remove.out
+++ b/regress/expected/cypher_remove.out
@@ -241,6 +241,128 @@ SELECT * FROM cypher('cypher_remove', $$MATCH (n) RETURN n$$) AS (a agtype);
  {"id": 3377699720527873, "label": "test_7", "properties": {}}::vertex
 (15 rows)
 
+-- prepared statements
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+PREPARE p_1 AS SELECT * FROM cypher('cypher_remove', $$MATCH (n) REMOVE n.i RETURN n $$) AS (a agtype);
+EXECUTE p_1;
+                                         a                                          
+------------------------------------------------------------------------------------
+ {"id": 281474976710657, "label": "", "properties": {}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {}}::vertex
+ {"id": 281474976710659, "label": "", "properties": {}}::vertex
+ {"id": 844424930131969, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131971, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131970, "label": "test_1", "properties": {"a": 0, "j": 5}}::vertex
+ {"id": 1125899906842625, "label": "test_2", "properties": {}}::vertex
+ {"id": 1125899906842626, "label": "test_2", "properties": {"a": 0}}::vertex
+ {"id": 1125899906842627, "label": "test_2", "properties": {}}::vertex
+ {"id": 1407374883553282, "label": "test_3", "properties": {}}::vertex
+ {"id": 1407374883553281, "label": "test_3", "properties": {}}::vertex
+ {"id": 1970324836974593, "label": "test_4", "properties": {}}::vertex
+ {"id": 1970324836974594, "label": "test_4", "properties": {}}::vertex
+ {"id": 2533274790395905, "label": "test_5", "properties": {"k": 3}}::vertex
+ {"id": 2814749767106561, "label": "test_6", "properties": {"j": 5}}::vertex
+ {"id": 3377699720527873, "label": "test_7", "properties": {}}::vertex
+(16 rows)
+
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+EXECUTE p_1;
+                                         a                                          
+------------------------------------------------------------------------------------
+ {"id": 281474976710657, "label": "", "properties": {}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {}}::vertex
+ {"id": 281474976710659, "label": "", "properties": {}}::vertex
+ {"id": 281474976710660, "label": "", "properties": {}}::vertex
+ {"id": 844424930131969, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131971, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131970, "label": "test_1", "properties": {"a": 0, "j": 5}}::vertex
+ {"id": 1125899906842625, "label": "test_2", "properties": {}}::vertex
+ {"id": 1125899906842626, "label": "test_2", "properties": {"a": 0}}::vertex
+ {"id": 1125899906842627, "label": "test_2", "properties": {}}::vertex
+ {"id": 1407374883553282, "label": "test_3", "properties": {}}::vertex
+ {"id": 1407374883553281, "label": "test_3", "properties": {}}::vertex
+ {"id": 1970324836974593, "label": "test_4", "properties": {}}::vertex
+ {"id": 1970324836974594, "label": "test_4", "properties": {}}::vertex
+ {"id": 2533274790395905, "label": "test_5", "properties": {"k": 3}}::vertex
+ {"id": 2814749767106561, "label": "test_6", "properties": {"j": 5}}::vertex
+ {"id": 3377699720527873, "label": "test_7", "properties": {}}::vertex
+(17 rows)
+
+-- pl/pgsql
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+CREATE FUNCTION remove_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_remove', $$MATCH (n) REMOVE n.i RETURN n$$) AS (a agtype);
+END
+$BODY$;
+SELECT remove_test();
+                                    remove_test                                     
+------------------------------------------------------------------------------------
+ {"id": 281474976710657, "label": "", "properties": {}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {}}::vertex
+ {"id": 281474976710659, "label": "", "properties": {}}::vertex
+ {"id": 281474976710660, "label": "", "properties": {}}::vertex
+ {"id": 281474976710661, "label": "", "properties": {}}::vertex
+ {"id": 844424930131969, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131971, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131970, "label": "test_1", "properties": {"a": 0, "j": 5}}::vertex
+ {"id": 1125899906842625, "label": "test_2", "properties": {}}::vertex
+ {"id": 1125899906842626, "label": "test_2", "properties": {"a": 0}}::vertex
+ {"id": 1125899906842627, "label": "test_2", "properties": {}}::vertex
+ {"id": 1407374883553282, "label": "test_3", "properties": {}}::vertex
+ {"id": 1407374883553281, "label": "test_3", "properties": {}}::vertex
+ {"id": 1970324836974593, "label": "test_4", "properties": {}}::vertex
+ {"id": 1970324836974594, "label": "test_4", "properties": {}}::vertex
+ {"id": 2533274790395905, "label": "test_5", "properties": {"k": 3}}::vertex
+ {"id": 2814749767106561, "label": "test_6", "properties": {"j": 5}}::vertex
+ {"id": 3377699720527873, "label": "test_7", "properties": {}}::vertex
+(18 rows)
+
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
+ a 
+---
+(0 rows)
+
+SELECT remove_test();
+                                    remove_test                                     
+------------------------------------------------------------------------------------
+ {"id": 281474976710657, "label": "", "properties": {}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {}}::vertex
+ {"id": 281474976710659, "label": "", "properties": {}}::vertex
+ {"id": 281474976710660, "label": "", "properties": {}}::vertex
+ {"id": 281474976710661, "label": "", "properties": {}}::vertex
+ {"id": 281474976710662, "label": "", "properties": {}}::vertex
+ {"id": 844424930131969, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131971, "label": "test_1", "properties": {}}::vertex
+ {"id": 844424930131970, "label": "test_1", "properties": {"a": 0, "j": 5}}::vertex
+ {"id": 1125899906842625, "label": "test_2", "properties": {}}::vertex
+ {"id": 1125899906842626, "label": "test_2", "properties": {"a": 0}}::vertex
+ {"id": 1125899906842627, "label": "test_2", "properties": {}}::vertex
+ {"id": 1407374883553282, "label": "test_3", "properties": {}}::vertex
+ {"id": 1407374883553281, "label": "test_3", "properties": {}}::vertex
+ {"id": 1970324836974593, "label": "test_4", "properties": {}}::vertex
+ {"id": 1970324836974594, "label": "test_4", "properties": {}}::vertex
+ {"id": 2533274790395905, "label": "test_5", "properties": {"k": 3}}::vertex
+ {"id": 2814749767106561, "label": "test_6", "properties": {"j": 5}}::vertex
+ {"id": 3377699720527873, "label": "test_7", "properties": {}}::vertex
+(19 rows)
+
 --Errors
 SELECT * FROM cypher('cypher_remove', $$REMOVE n.i$$) AS (a agtype);
 ERROR:  REMOVE cannot be the first clause in a Cypher query
@@ -261,6 +383,7 @@ LINE 1: SELECT * FROM cypher('cypher_remove', $$MATCH (n) REMOVE n.i...
 --
 -- Clean up
 --
+DROP FUNCTION remove_test;
 SELECT drop_graph('cypher_remove', true);
 NOTICE:  drop cascades to 12 other objects
 DETAIL:  drop cascades to table cypher_remove._ag_label_vertex
diff --git a/regress/expected/cypher_set.out b/regress/expected/cypher_set.out
index 40d4e63..ecc3083 100644
--- a/regress/expected/cypher_set.out
+++ b/regress/expected/cypher_set.out
@@ -238,6 +238,108 @@ SELECT * FROM cypher('cypher_set', $$MATCH (n) MATCH (n)-[]->(m) SET n.t = 150 R
  {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 50, "j": 5, "t": 150, "y": 99, "z": 99}}::vertex
 (6 rows)
 
+-- prepared statements
+PREPARE p_1 AS SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = 3 RETURN n $$) AS (a agtype);
+EXECUTE p_1;
+                                                         a                                                         
+-------------------------------------------------------------------------------------------------------------------
+ {"id": 281474976710659, "label": "", "properties": {"i": 3, "y": 2}}::vertex
+ {"id": 281474976710657, "label": "", "properties": {"i": 3, "t": 150}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {"i": 3, "t": 150, "y": 1}}::vertex
+ {"id": 844424930131969, "label": "v", "properties": {"i": 3, "t": 150}}::vertex
+ {"id": 844424930131971, "label": "v", "properties": {"i": 3, "t": 150}}::vertex
+ {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 3, "j": 5, "t": 150, "y": 99, "z": 99}}::vertex
+ {"id": 1407374883553281, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+ {"id": 1407374883553282, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+ {"id": 1407374883553283, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+ {"id": 1407374883553284, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+(10 rows)
+
+EXECUTE p_1;
+                                                         a                                                         
+-------------------------------------------------------------------------------------------------------------------
+ {"id": 281474976710659, "label": "", "properties": {"i": 3, "y": 2}}::vertex
+ {"id": 281474976710657, "label": "", "properties": {"i": 3, "t": 150}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {"i": 3, "t": 150, "y": 1}}::vertex
+ {"id": 844424930131969, "label": "v", "properties": {"i": 3, "t": 150}}::vertex
+ {"id": 844424930131971, "label": "v", "properties": {"i": 3, "t": 150}}::vertex
+ {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 3, "j": 5, "t": 150, "y": 99, "z": 99}}::vertex
+ {"id": 1407374883553281, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+ {"id": 1407374883553282, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+ {"id": 1407374883553283, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+ {"id": 1407374883553284, "label": "other_v", "properties": {"i": 3, "k": 10}}::vertex
+(10 rows)
+
+PREPARE p_2 AS SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = $var_name RETURN n $$, $1) AS (a agtype);
+EXECUTE p_2('{"var_name": 4}');
+                                                         a                                                         
+-------------------------------------------------------------------------------------------------------------------
+ {"id": 281474976710659, "label": "", "properties": {"i": 4, "y": 2}}::vertex
+ {"id": 281474976710657, "label": "", "properties": {"i": 4, "t": 150}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {"i": 4, "t": 150, "y": 1}}::vertex
+ {"id": 844424930131969, "label": "v", "properties": {"i": 4, "t": 150}}::vertex
+ {"id": 844424930131971, "label": "v", "properties": {"i": 4, "t": 150}}::vertex
+ {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 4, "j": 5, "t": 150, "y": 99, "z": 99}}::vertex
+ {"id": 1407374883553281, "label": "other_v", "properties": {"i": 4, "k": 10}}::vertex
+ {"id": 1407374883553282, "label": "other_v", "properties": {"i": 4, "k": 10}}::vertex
+ {"id": 1407374883553283, "label": "other_v", "properties": {"i": 4, "k": 10}}::vertex
+ {"id": 1407374883553284, "label": "other_v", "properties": {"i": 4, "k": 10}}::vertex
+(10 rows)
+
+EXECUTE p_2('{"var_name": 6}');
+                                                         a                                                         
+-------------------------------------------------------------------------------------------------------------------
+ {"id": 281474976710659, "label": "", "properties": {"i": 6, "y": 2}}::vertex
+ {"id": 281474976710657, "label": "", "properties": {"i": 6, "t": 150}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {"i": 6, "t": 150, "y": 1}}::vertex
+ {"id": 844424930131969, "label": "v", "properties": {"i": 6, "t": 150}}::vertex
+ {"id": 844424930131971, "label": "v", "properties": {"i": 6, "t": 150}}::vertex
+ {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 6, "j": 5, "t": 150, "y": 99, "z": 99}}::vertex
+ {"id": 1407374883553281, "label": "other_v", "properties": {"i": 6, "k": 10}}::vertex
+ {"id": 1407374883553282, "label": "other_v", "properties": {"i": 6, "k": 10}}::vertex
+ {"id": 1407374883553283, "label": "other_v", "properties": {"i": 6, "k": 10}}::vertex
+ {"id": 1407374883553284, "label": "other_v", "properties": {"i": 6, "k": 10}}::vertex
+(10 rows)
+
+CREATE FUNCTION set_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = 7 RETURN n $$) AS (a agtype);
+END
+$BODY$;
+SELECT set_test();
+                                                     set_test                                                      
+-------------------------------------------------------------------------------------------------------------------
+ {"id": 281474976710659, "label": "", "properties": {"i": 7, "y": 2}}::vertex
+ {"id": 281474976710657, "label": "", "properties": {"i": 7, "t": 150}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {"i": 7, "t": 150, "y": 1}}::vertex
+ {"id": 844424930131969, "label": "v", "properties": {"i": 7, "t": 150}}::vertex
+ {"id": 844424930131971, "label": "v", "properties": {"i": 7, "t": 150}}::vertex
+ {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 7, "j": 5, "t": 150, "y": 99, "z": 99}}::vertex
+ {"id": 1407374883553281, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+ {"id": 1407374883553282, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+ {"id": 1407374883553283, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+ {"id": 1407374883553284, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+(10 rows)
+
+SELECT set_test();
+                                                     set_test                                                      
+-------------------------------------------------------------------------------------------------------------------
+ {"id": 281474976710659, "label": "", "properties": {"i": 7, "y": 2}}::vertex
+ {"id": 281474976710657, "label": "", "properties": {"i": 7, "t": 150}}::vertex
+ {"id": 281474976710658, "label": "", "properties": {"i": 7, "t": 150, "y": 1}}::vertex
+ {"id": 844424930131969, "label": "v", "properties": {"i": 7, "t": 150}}::vertex
+ {"id": 844424930131971, "label": "v", "properties": {"i": 7, "t": 150}}::vertex
+ {"id": 844424930131970, "label": "v", "properties": {"a": 0, "i": 7, "j": 5, "t": 150, "y": 99, "z": 99}}::vertex
+ {"id": 1407374883553281, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+ {"id": 1407374883553282, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+ {"id": 1407374883553283, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+ {"id": 1407374883553284, "label": "other_v", "properties": {"i": 7, "k": 10}}::vertex
+(10 rows)
+
 --Errors
 SELECT * FROM cypher('cypher_set', $$SET n.i = NULL$$) AS (a agtype);
 ERROR:  SET cannot be the first clause in a Cypher query
@@ -254,6 +356,7 @@ LINE 1: SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = 3, ...
 --
 -- Clean up
 --
+DROP FUNCTION set_test;
 SELECT drop_graph('cypher_set', true);
 NOTICE:  drop cascades to 5 other objects
 DETAIL:  drop cascades to table cypher_set._ag_label_vertex
diff --git a/regress/sql/cypher_create.sql b/regress/sql/cypher_create.sql
index 8de01d3..81611c0 100644
--- a/regress/sql/cypher_create.sql
+++ b/regress/sql/cypher_create.sql
@@ -185,6 +185,29 @@ SELECT name, kind FROM ag_label ORDER BY name;
 --Validate every vertex has the correct label
 SELECT * FROM cypher('cypher_create', $$MATCH (n) RETURN n$$) AS (n agtype);
 
+-- prepared statements
+PREPARE p_1 AS SELECT * FROM cypher('cypher_create', $$CREATE (v:new_vertex {key: 'value'}) RETURN v$$) AS (a agtype);
+EXECUTE p_1;
+EXECUTE p_1;
+
+PREPARE p_2 AS SELECT * FROM cypher('cypher_create', $$CREATE (v:new_vertex {key: $var_name}) RETURN v$$, $1) AS (a agtype);
+EXECUTE p_2('{"var_name": "Hello Prepared Statements"}');
+EXECUTE p_2('{"var_name": "Hello Prepared Statements 2"}');
+
+-- pl/pgsql
+CREATE FUNCTION create_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_create', $$CREATE (v:new_vertex {key: 'value'}) RETURN v$$) AS (a agtype);
+END
+$BODY$;
+
+SELECT create_test();
+SELECT create_test();
+
 --
 -- Errors
 --
@@ -230,5 +253,12 @@ $$) as t(b agtype);
 SELECT * FROM cypher('cypher_create', $$CREATE ()$$) AS (a int);
 SELECT * FROM cypher('cypher_create', $$CREATE ()$$) AS (a agtype, b int);
 
--- intial and last vertex point to the middle vertex
+--
+-- Clean up
+--
+DROP FUNCTION create_test;
 SELECT drop_graph('cypher_create', true);
+
+--
+-- End
+--
diff --git a/regress/sql/cypher_delete.sql b/regress/sql/cypher_delete.sql
index 8d3c9ae..f062722 100644
--- a/regress/sql/cypher_delete.sql
+++ b/regress/sql/cypher_delete.sql
@@ -165,14 +165,41 @@ SELECT * FROM cypher('cypher_delete', $$CREATE (n:v)$$) AS (a agtype);
 SELECT * FROM cypher('cypher_delete', $$MATCH (n) DELETE n CREATE (n)-[:e]->(:v) RETURN n$$) AS (a agtype);
 
 --Cleanup
-SELECT * FROM cypher('cypher_delete', $$MATCH(n) RETURN n$$) AS (a agtype);
+SELECT * FROM cypher('cypher_delete', $$MATCH(n) DELETE n RETURN n$$) AS (a agtype);
 
 --Test 20 Undefined Reference:
 SELECT * FROM cypher('cypher_delete', $$MATCH (n) DELETE m RETURN n$$) AS (a agtype);
+
+--Test 21 Prepared Statements
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+
+PREPARE d AS SELECT * FROM cypher('cypher_delete', $$MATCH (v) DELETE (v) RETURN v$$) AS (a agtype);
+EXECUTE d;
+
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+EXECUTE d;
+
+--Test 22 pl/pgsql Functions
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+
+CREATE FUNCTION delete_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_delete', $$MATCH (v) DELETE (v) RETURN v$$) AS (a agtype);
+END
+$BODY$;
+
+SELECT delete_test();
+
+SELECT * FROM cypher('cypher_delete', $$CREATE (v:v)$$) AS (a agtype);
+SELECT delete_test();
 --
 -- Clean up
 --
-
+DROP FUNCTION delete_test;
 SELECT drop_graph('cypher_delete', true);
 
 --
diff --git a/regress/sql/cypher_remove.sql b/regress/sql/cypher_remove.sql
index 9e0f01c..260d7b8 100644
--- a/regress/sql/cypher_remove.sql
+++ b/regress/sql/cypher_remove.sql
@@ -99,7 +99,30 @@ SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
 SELECT * FROM cypher('cypher_remove', $$MATCH (n) REMOVE n.i RETURN n$$) AS (a agtype);
 SELECT * FROM cypher('cypher_remove', $$MATCH (n) RETURN n$$) AS (a agtype);
 
+-- prepared statements
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
+PREPARE p_1 AS SELECT * FROM cypher('cypher_remove', $$MATCH (n) REMOVE n.i RETURN n $$) AS (a agtype);
+EXECUTE p_1;
+
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
+EXECUTE p_1;
+-- pl/pgsql
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
 
+CREATE FUNCTION remove_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_remove', $$MATCH (n) REMOVE n.i RETURN n$$) AS (a agtype);
+END
+$BODY$;
+
+SELECT remove_test();
+
+SELECT * FROM cypher('cypher_remove', $$CREATE ( {i : 1 })$$) AS (a agtype);
+SELECT remove_test();
 --Errors
 SELECT * FROM cypher('cypher_remove', $$REMOVE n.i$$) AS (a agtype);
 
@@ -111,6 +134,7 @@ SELECT * FROM cypher('cypher_remove', $$MATCH (n) REMOVE n.i = 3, n.j = 5 $$) AS
 --
 -- Clean up
 --
+DROP FUNCTION remove_test;
 SELECT drop_graph('cypher_remove', true);
 
 --
diff --git a/regress/sql/cypher_set.sql b/regress/sql/cypher_set.sql
index 69f2e66..309617d 100644
--- a/regress/sql/cypher_set.sql
+++ b/regress/sql/cypher_set.sql
@@ -96,6 +96,31 @@ SELECT * FROM cypher('cypher_set', $$MATCH (n)-[]->(n) SET n.y = 99 RETURN n$$)
 
 SELECT * FROM cypher('cypher_set', $$MATCH (n) MATCH (n)-[]->(m) SET n.t = 150 RETURN n$$) AS (a agtype);
 
+-- prepared statements
+PREPARE p_1 AS SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = 3 RETURN n $$) AS (a agtype);
+EXECUTE p_1;
+
+EXECUTE p_1;
+
+PREPARE p_2 AS SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = $var_name RETURN n $$, $1) AS (a agtype);
+EXECUTE p_2('{"var_name": 4}');
+
+EXECUTE p_2('{"var_name": 6}');
+
+CREATE FUNCTION set_test()
+RETURNS TABLE(vertex agtype)
+LANGUAGE plpgsql
+VOLATILE
+AS $BODY$
+BEGIN
+	RETURN QUERY SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = 7 RETURN n $$) AS (a agtype);
+END
+$BODY$;
+
+SELECT set_test();
+
+SELECT set_test();
+
 --Errors
 SELECT * FROM cypher('cypher_set', $$SET n.i = NULL$$) AS (a agtype);
 
@@ -106,7 +131,7 @@ SELECT * FROM cypher('cypher_set', $$MATCH (n) SET n.i = 3, n.j = 5 $$) AS (a ag
 --
 -- Clean up
 --
-
+DROP FUNCTION set_test;
 SELECT drop_graph('cypher_set', true);
 
 --
diff --git a/src/backend/executor/cypher_create.c b/src/backend/executor/cypher_create.c
index 36f919b..a5769fe 100644
--- a/src/backend/executor/cypher_create.c
+++ b/src/backend/executor/cypher_create.c
@@ -316,10 +316,18 @@ Node *create_cypher_create_plan_state(CustomScan *cscan)
     cypher_create_custom_scan_state *cypher_css =
         palloc0(sizeof(cypher_create_custom_scan_state));
     cypher_create_target_nodes *target_nodes;
+    char *serialized_data;
+    Const *c;
 
     cypher_css->cs = cscan;
 
-    target_nodes = linitial(cscan->custom_private);
+    // get the serialized data structure from the Const and deserialize it.
+    c = linitial(cscan->custom_private);
+    serialized_data = (char *)c->constvalue;
+    target_nodes = stringToNode(serialized_data);
+
+    Assert(is_ag_node(target_nodes, cypher_create_target_nodes));
+
     cypher_css->path_values = NIL;
     cypher_css->pattern = target_nodes->paths;
     cypher_css->tuple_info = NIL;
diff --git a/src/backend/executor/cypher_delete.c b/src/backend/executor/cypher_delete.c
index 8c0e0a4..c0fe945 100644
--- a/src/backend/executor/cypher_delete.c
+++ b/src/backend/executor/cypher_delete.c
@@ -226,10 +226,18 @@ Node *create_cypher_delete_plan_state(CustomScan *cscan)
     cypher_delete_custom_scan_state *cypher_css =
         palloc0(sizeof(cypher_delete_custom_scan_state));
     cypher_delete_information *delete_data;
+    char *serialized_data;
+    Const *c;
 
     cypher_css->cs = cscan;
 
-    delete_data = linitial(cscan->custom_private);
+    // get the serialized data structure from the Const and deserialize it.
+    c = linitial(cscan->custom_private);
+    serialized_data = (char *)c->constvalue;
+    delete_data = stringToNode(serialized_data);
+
+    Assert(is_ag_node(delete_data, cypher_delete_information));
+
     cypher_css->delete_data = delete_data;
     cypher_css->flags = delete_data->flags;
 
diff --git a/src/backend/executor/cypher_set.c b/src/backend/executor/cypher_set.c
index 1e6cead..e2d8e21 100644
--- a/src/backend/executor/cypher_set.c
+++ b/src/backend/executor/cypher_set.c
@@ -473,10 +473,18 @@ Node *create_cypher_set_plan_state(CustomScan *cscan)
     cypher_set_custom_scan_state *cypher_css =
         palloc0(sizeof(cypher_set_custom_scan_state));
     cypher_update_information *set_list;
+    char *serialized_data;
+    Const *c;
 
     cypher_css->cs = cscan;
 
-    set_list = linitial(cscan->custom_private);
+    // get the serialized data structure from the Const and deserialize it.
+    c = linitial(cscan->custom_private);
+    serialized_data = (char *)c->constvalue;
+    set_list = stringToNode(serialized_data);
+
+    Assert(is_ag_node(set_list, cypher_update_information));
+
     cypher_css->set_list = set_list;
     cypher_css->flags = set_list->flags;
 
diff --git a/src/backend/nodes/ag_nodes.c b/src/backend/nodes/ag_nodes.c
index 06a0c85..fd8815c 100644
--- a/src/backend/nodes/ag_nodes.c
+++ b/src/backend/nodes/ag_nodes.c
@@ -22,12 +22,12 @@
 #include "nodes/extensible.h"
 
 #include "nodes/ag_nodes.h"
+#include "nodes/cypher_copyfuncs.h"
+#include "nodes/cypher_outfuncs.h"
+#include "nodes/cypher_readfuncs.h"
 #include "nodes/cypher_nodes.h"
 
-static void copy_ag_node(ExtensibleNode *newnode,
-                         const ExtensibleNode *oldnode);
 static bool equal_ag_node(const ExtensibleNode *a, const ExtensibleNode *b);
-static void read_ag_node(ExtensibleNode *node);
 
 // This list must match ag_node_tag.
 const char *node_names[] = {
@@ -49,9 +49,21 @@ const char *node_names[] = {
     "cypher_string_match",
     "cypher_typecast",
     "cypher_integer_const",
-    "cypher_sub_pattern"
+    "cypher_sub_pattern",
+    "cypher_create_target_nodes",
+    "cypher_create_path",
+    "cypher_target_node",
+    "cypher_update_information",
+    "cypher_update_item",
+    "cypher_delete_information",
+    "cypher_delete_item"
 };
 
+/*
+ * Each node defined with this will have
+ * an out function defined, but copy, equal,
+ * and read will throw errors.
+ */
 #define DEFINE_NODE_METHODS(type) \
     { \
         CppAsString(type), \
@@ -62,6 +74,21 @@ const char *node_names[] = {
         read_ag_node \
     }
 
+/*
+ *  Each node defined with this will have a
+ *  copy, read, and write function defined.
+ *  Equal will still throw an error.
+ */
+#define DEFINE_NODE_METHODS_EXTENDED(type) \
+    { \
+        CppAsString(type), \
+        sizeof(type), \
+        CppConcat(copy_, type), \
+        equal_ag_node, \
+        CppConcat(out_, type), \
+        CppConcat(read_, type) \
+    }
+
 // This list must match ag_node_tag.
 const ExtensibleNodeMethods node_methods[] = {
     DEFINE_NODE_METHODS(cypher_return),
@@ -81,25 +108,21 @@ const ExtensibleNodeMethods node_methods[] = {
     DEFINE_NODE_METHODS(cypher_string_match),
     DEFINE_NODE_METHODS(cypher_typecast),
     DEFINE_NODE_METHODS(cypher_integer_const),
-    DEFINE_NODE_METHODS(cypher_sub_pattern)
+    DEFINE_NODE_METHODS(cypher_sub_pattern),
+    DEFINE_NODE_METHODS_EXTENDED(cypher_create_target_nodes),
+    DEFINE_NODE_METHODS_EXTENDED(cypher_create_path),
+    DEFINE_NODE_METHODS_EXTENDED(cypher_target_node),
+    DEFINE_NODE_METHODS_EXTENDED(cypher_update_information),
+    DEFINE_NODE_METHODS_EXTENDED(cypher_update_item),
+    DEFINE_NODE_METHODS_EXTENDED(cypher_delete_information),
+    DEFINE_NODE_METHODS_EXTENDED(cypher_delete_item)
 };
 
-static void copy_ag_node(ExtensibleNode *newnode,
-                         const ExtensibleNode *oldnode)
-{
-    ereport(ERROR, (errmsg("unexpected copyObject() over ag_node")));
-}
-
 static bool equal_ag_node(const ExtensibleNode *a, const ExtensibleNode *b)
 {
     ereport(ERROR, (errmsg("unexpected equal() over ag_node's")));
 }
 
-static void read_ag_node(ExtensibleNode *node)
-{
-    ereport(ERROR, (errmsg("unexpected parseNodeString() for ag_node")));
-}
-
 void register_ag_nodes(void)
 {
     static bool initialized = false;
diff --git a/src/backend/nodes/cypher_copyfuncs.c b/src/backend/nodes/cypher_copyfuncs.c
new file mode 100644
index 0000000..59632ac
--- /dev/null
+++ b/src/backend/nodes/cypher_copyfuncs.c
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "postgres.h"
+
+#include "nodes/bitmapset.h"
+#include "nodes/extensible.h"
+#include "nodes/nodes.h"
+#include "utils/palloc.h"
+
+#include "nodes/cypher_copyfuncs.h"
+#include "nodes/cypher_nodes.h"
+
+/*
+ * Copied From Postgres
+ *
+ * Macros to simplify copying of different kinds of fields.  Use these
+ * wherever possible to reduce the chance for silly typos.  Note that these
+ * hard-wire the convention that the local variables in a Copy routine are
+ * named 'extended_newnode' and 'extended_from'.
+ */
+
+// Declare the local fields needed to copy extensible nodes
+#define COPY_LOCALS(nodeTypeName) \
+    nodeTypeName *extended_newnode = (nodeTypeName *)newnode; \
+    nodeTypeName *extended_from = (nodeTypeName *)from; \
+    Assert(is_ag_node(newnode, nodeTypeName)); \
+    Assert(is_ag_node(from, nodeTypeName));
+
+
+// Copy a simple scalar field (int, float, bool, enum, etc)
+#define COPY_SCALAR_FIELD(fldname) \
+        (extended_newnode->fldname = extended_from->fldname)
+
+// Copy a field that is a pointer to some kind of Node or Node tree
+#define COPY_NODE_FIELD(fldname) \
+        (extended_newnode->fldname = copyObject(extended_from->fldname))
+
+// Copy a field that is a pointer to a Bitmapset
+#define COPY_BITMAPSET_FIELD(fldname) \
+        (extended_newnode->fldname = bms_copy(extended_from->fldname))
+
+// Copy a field that is a pointer to a C string, or perhaps NULL
+#define COPY_STRING_FIELD(fldname) \
+        (extended_newnode->fldname = extended_from->fldname ? \
+            pstrdup(extended_from->fldname) : (char *) NULL)
+
+/*
+ * Default copy function for cypher nodes. For most nodes, we don't expect
+ * the node to ever be copied. So throw an error.
+ */
+void copy_ag_node(ExtensibleNode *newnode,
+                         const ExtensibleNode *oldnode)
+{
+    ereport(ERROR, (errmsg("unexpected copyObject() over ag_node")));
+}
+
+// copy function for cypher_create_target_nodes
+void copy_cypher_create_target_nodes(ExtensibleNode *newnode, const ExtensibleNode *from)
+{
+    COPY_LOCALS(cypher_create_target_nodes);
+
+    COPY_SCALAR_FIELD(flags);
+    COPY_SCALAR_FIELD(graph_oid);
+
+    COPY_NODE_FIELD(paths);
+}
+
+// copy function for cypher_create_path
+void copy_cypher_create_path(ExtensibleNode *newnode, const ExtensibleNode *from)
+{
+    COPY_LOCALS(cypher_create_path);
+
+    COPY_SCALAR_FIELD(tuple_position);
+
+    COPY_NODE_FIELD(target_nodes);
+}
+
+// copy function for cypher_target_node
+void copy_cypher_target_node(ExtensibleNode *newnode, const ExtensibleNode *from)
+{
+    COPY_LOCALS(cypher_target_node);
+
+    COPY_SCALAR_FIELD(type);
+    COPY_SCALAR_FIELD(flags);
+    COPY_SCALAR_FIELD(dir);
+    COPY_SCALAR_FIELD(id_var_no);
+    COPY_SCALAR_FIELD(prop_var_no);
+    COPY_SCALAR_FIELD(relid);
+    COPY_SCALAR_FIELD(tuple_position);
+
+    COPY_STRING_FIELD(label_name);
+    COPY_STRING_FIELD(variable_name);
+
+    COPY_NODE_FIELD(resultRelInfo);
+    COPY_NODE_FIELD(elemTupleSlot);
+    COPY_NODE_FIELD(te);
+    COPY_NODE_FIELD(targetList);
+    COPY_NODE_FIELD(expr_states);
+}
+
+// copy function for cypher_update_information
+void copy_cypher_update_information(ExtensibleNode *newnode, const ExtensibleNode *from)
+{
+    COPY_LOCALS(cypher_update_information);
+
+    COPY_NODE_FIELD(set_items);
+    COPY_SCALAR_FIELD(flags);
+    COPY_SCALAR_FIELD(tuple_position);
+    COPY_STRING_FIELD(graph_name);
+    COPY_STRING_FIELD(clause_name);
+}
+
+// copy function for cypher_update_item
+void copy_cypher_update_item(ExtensibleNode *newnode, const ExtensibleNode *from)
+{
+    COPY_LOCALS(cypher_update_item);
+
+    COPY_SCALAR_FIELD(prop_position);
+    COPY_SCALAR_FIELD(entity_position);
+    COPY_STRING_FIELD(var_name);
+    COPY_STRING_FIELD(prop_name);
+    COPY_NODE_FIELD(qualified_name);
+    COPY_SCALAR_FIELD(remove_item);
+}
+
+// copy function for cypher_delete_information
+void copy_cypher_delete_information(ExtensibleNode *newnode, const ExtensibleNode *from)
+{
+    COPY_LOCALS(cypher_delete_information);
+
+    COPY_NODE_FIELD(delete_items);
+    COPY_SCALAR_FIELD(flags);
+    COPY_STRING_FIELD(graph_name);
+    COPY_SCALAR_FIELD(graph_oid);
+    COPY_SCALAR_FIELD(detach);
+}
+
+// copy function for cypher_delete_item
+void copy_cypher_delete_item(ExtensibleNode *newnode, const ExtensibleNode *from)
+{
+    COPY_LOCALS(cypher_delete_item);
+
+    COPY_NODE_FIELD(entity_position);
+    COPY_STRING_FIELD(var_name);
+}
diff --git a/src/backend/nodes/cypher_outfuncs.c b/src/backend/nodes/cypher_outfuncs.c
new file mode 100644
index 0000000..d0ef9e8
--- /dev/null
+++ b/src/backend/nodes/cypher_outfuncs.c
@@ -0,0 +1,380 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "postgres.h"
+
+#include "lib/stringinfo.h"
+#include "nodes/extensible.h"
+#include "nodes/nodes.h"
+
+#include "nodes/cypher_nodes.h"
+#include "nodes/cypher_outfuncs.h"
+
+static void outChar(StringInfo str, char c);
+
+#define DEFINE_AG_NODE(type) \
+    type *_node = (type *)node
+
+#define WRITE_NODE_FIELD(field_name) \
+    do \
+    { \
+        appendStringInfoString(str, " :" CppAsString(field_name) " "); \
+        outNode(str, _node->field_name); \
+    } while (0)
+
+#define WRITE_STRING_FIELD(field_name) \
+    do \
+    { \
+        appendStringInfoString(str, " :" CppAsString(field_name) " "); \
+        outToken(str, _node->field_name); \
+    } while (0)
+
+// Write a char field (ie, one ascii character)
+#define WRITE_CHAR_FIELD(fldname) \
+    do { \
+        (appendStringInfo(str, " :" CppAsString(fldname) " "), \
+         outChar(str, _node->fldname)); \
+    } while (0)
+
+#define WRITE_BOOL_FIELD(field_name) \
+    do \
+    { \
+        appendStringInfo(str, " :" CppAsString(field_name) " %s", \
+                         _node->field_name ? "true" : "false"); \
+    } while (0)
+
+// write an enumerated-type field as an integer code
+#define WRITE_ENUM_FIELD(field_name, enum_type) \
+    do \
+    { \
+        appendStringInfo(str, " :" CppAsString(field_name) " %d", \
+                         (int)_node->field_name); \
+    } while (0)
+
+#define WRITE_LOCATION_FIELD(field_name) \
+    do \
+    { \
+        appendStringInfo(str, " :" CppAsString(field_name) " %d", \
+                         _node->field_name); \
+    } while (0)
+
+#define WRITE_INT64_FIELD(field_name) \
+    do \
+    { \
+        appendStringInfo(str, " :" CppAsString(field_name) " %ld", \
+                         _node->field_name); \
+    } while (0)
+
+// Write an integer field (anything written as ":fldname %d")
+#define WRITE_INT32_FIELD(field_name) \
+    do { \
+        appendStringInfo(str, " :" CppAsString(field_name) " %d", \
+                         _node->field_name); \
+    } while (0)
+
+// Write an OID field (don't hard-wire assumption that OID is same as uint)
+#define WRITE_OID_FIELD(fldname) \
+    do { \
+        appendStringInfo(str, " :" CppAsString(fldname) " %u", \
+                          _node->fldname); \
+    } while(0);
+
+
+
+// serialization function for the cypher_return ExtensibleNode.
+void out_cypher_return(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_return);
+
+    WRITE_BOOL_FIELD(distinct);
+    WRITE_NODE_FIELD(items);
+    WRITE_NODE_FIELD(order_by);
+    WRITE_NODE_FIELD(skip);
+    WRITE_NODE_FIELD(limit);
+}
+
+// serialization function for the cypher_with ExtensibleNode.
+void out_cypher_with(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_with);
+
+    WRITE_BOOL_FIELD(distinct);
+    WRITE_NODE_FIELD(items);
+    WRITE_NODE_FIELD(order_by);
+    WRITE_NODE_FIELD(skip);
+    WRITE_NODE_FIELD(limit);
+    WRITE_NODE_FIELD(where);
+}
+
+// serialization function for the cypher_match ExtensibleNode.
+void out_cypher_match(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_match);
+
+    WRITE_NODE_FIELD(pattern);
+    WRITE_NODE_FIELD(where);
+}
+
+// serialization function for the cypher_create ExtensibleNode.
+void out_cypher_create(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_create);
+
+    WRITE_NODE_FIELD(pattern);
+}
+
+// serialization function for the cypher_set ExtensibleNode.
+void out_cypher_set(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_set);
+
+    WRITE_NODE_FIELD(items);
+    WRITE_BOOL_FIELD(is_remove);
+}
+
+// serialization function for the cypher_set_item ExtensibleNode.
+void out_cypher_set_item(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_set_item);
+
+    WRITE_NODE_FIELD(prop);
+    WRITE_NODE_FIELD(expr);
+    WRITE_BOOL_FIELD(is_add);
+}
+
+// serialization function for the cypher_delete ExtensibleNode.
+void out_cypher_delete(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_delete);
+
+    WRITE_BOOL_FIELD(detach);
+    WRITE_NODE_FIELD(exprs);
+}
+
+// serialization function for the cypher_path ExtensibleNode.
+void out_cypher_path(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_path);
+
+    WRITE_NODE_FIELD(path);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_node ExtensibleNode.
+void out_cypher_node(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_node);
+
+    WRITE_STRING_FIELD(name);
+    WRITE_STRING_FIELD(label);
+    WRITE_NODE_FIELD(props);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_relationship ExtensibleNode.
+void out_cypher_relationship(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_relationship);
+
+    WRITE_STRING_FIELD(name);
+    WRITE_STRING_FIELD(label);
+    WRITE_NODE_FIELD(props);
+    WRITE_NODE_FIELD(varlen);
+    WRITE_ENUM_FIELD(dir, cypher_rel_dir);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_bool_const ExtensibleNode.
+void out_cypher_bool_const(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_bool_const);
+
+    WRITE_BOOL_FIELD(boolean);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_param ExtensibleNode.
+void out_cypher_param(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_param);
+
+    WRITE_STRING_FIELD(name);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_map ExtensibleNode.
+void out_cypher_map(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_map);
+
+    WRITE_NODE_FIELD(keyvals);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_list ExtensibleNode.
+void out_cypher_list(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_list);
+
+    WRITE_NODE_FIELD(elems);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_string_match ExtensibleNode.
+void out_cypher_string_match(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_string_match);
+
+    WRITE_ENUM_FIELD(operation, cypher_string_match_op);
+    WRITE_NODE_FIELD(lhs);
+    WRITE_NODE_FIELD(rhs);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_typecast ExtensibleNode.
+void out_cypher_typecast(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_typecast);
+
+    WRITE_NODE_FIELD(expr);
+    WRITE_STRING_FIELD(typecast);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_integer_const ExtensibleNode.
+void out_cypher_integer_const(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_integer_const);
+
+    WRITE_INT64_FIELD(integer);
+    WRITE_LOCATION_FIELD(location);
+}
+
+// serialization function for the cypher_sub_pattern ExtensibleNode.
+void out_cypher_sub_pattern(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_sub_pattern);
+
+    WRITE_ENUM_FIELD(kind, csp_kind);
+    WRITE_NODE_FIELD(pattern);
+}
+
+// serialization function for the cypher_create_target_nodes ExtensibleNode.
+void out_cypher_create_target_nodes(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_create_target_nodes);
+
+    WRITE_NODE_FIELD(paths);
+    WRITE_INT32_FIELD(flags);
+    WRITE_OID_FIELD(graph_oid);
+}
+
+// serialization function for the cypher_create_path ExtensibleNode.
+void out_cypher_create_path(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_create_path);
+
+    WRITE_NODE_FIELD(target_nodes);
+    WRITE_INT32_FIELD(tuple_position);
+}
+
+// serialization function for the cypher_target_node ExtensibleNode.
+void out_cypher_target_node(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_target_node);
+
+    WRITE_CHAR_FIELD(type);
+    WRITE_INT32_FIELD(flags);
+    WRITE_ENUM_FIELD(dir, cypher_rel_dir);
+    WRITE_INT32_FIELD(id_var_no);
+    WRITE_INT32_FIELD(prop_var_no);
+    WRITE_NODE_FIELD(targetList);
+    WRITE_NODE_FIELD(te);
+    WRITE_NODE_FIELD(expr_states);
+    WRITE_NODE_FIELD(resultRelInfo);
+    WRITE_NODE_FIELD(elemTupleSlot);
+    WRITE_OID_FIELD(relid);
+    WRITE_STRING_FIELD(label_name);
+    WRITE_STRING_FIELD(variable_name);
+    WRITE_INT32_FIELD(tuple_position);
+}
+
+// serialization function for the cypher_update_information ExtensibleNode.
+void out_cypher_update_information(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_update_information);
+
+    WRITE_NODE_FIELD(set_items);
+    WRITE_INT32_FIELD(flags);
+    WRITE_INT32_FIELD(tuple_position);
+    WRITE_STRING_FIELD(graph_name);
+    WRITE_STRING_FIELD(clause_name);
+}
+
+// serialization function for the cypher_update_item ExtensibleNode.
+void out_cypher_update_item(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_update_item);
+
+    WRITE_INT32_FIELD(prop_position);
+    WRITE_INT32_FIELD(entity_position);
+    WRITE_STRING_FIELD(var_name);
+    WRITE_STRING_FIELD(prop_name);
+    WRITE_NODE_FIELD(qualified_name);
+    WRITE_BOOL_FIELD(remove_item);
+}
+
+// serialization function for the cypher_delete_information ExtensibleNode.
+void out_cypher_delete_information(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_delete_information);
+
+    WRITE_NODE_FIELD(delete_items);
+    WRITE_INT32_FIELD(flags);
+    WRITE_STRING_FIELD(graph_name);
+    WRITE_OID_FIELD(graph_oid);
+    WRITE_BOOL_FIELD(detach);
+}
+
+// serialization function for the cypher_delete_item ExtensibleNode.
+void out_cypher_delete_item(StringInfo str, const ExtensibleNode *node)
+{
+    DEFINE_AG_NODE(cypher_delete_item);
+
+    WRITE_NODE_FIELD(entity_position);
+    WRITE_STRING_FIELD(var_name);
+}
+
+/*
+ * Copied from Postgres
+ *
+ * Convert one char.  Goes through outToken() so that special characters are
+ * escaped.
+ */
+static void
+outChar(StringInfo str, char c)
+{
+        char            in[2];
+
+        in[0] = c;
+        in[1] = '\0';
+
+        outToken(str, in);
+}
+
diff --git a/src/backend/nodes/cypher_readfuncs.c b/src/backend/nodes/cypher_readfuncs.c
new file mode 100644
index 0000000..5486c69
--- /dev/null
+++ b/src/backend/nodes/cypher_readfuncs.c
@@ -0,0 +1,277 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "postgres.h"
+
+#include "nodes/readfuncs.h"
+
+#include "nodes/cypher_readfuncs.h"
+#include "nodes/cypher_nodes.h"
+
+/*
+ * Copied From Postgres
+ *
+ * Macros for declaring appropriate local variables.
+ */
+// Declare the extensible node and local fields for the pg_strtok
+#define READ_LOCALS(nodeTypeName) \
+        nodeTypeName *local_node = (nodeTypeName *)node; \
+        char *token; \
+        int  length;
+
+/*
+ * The READ_*_FIELD defines first skips the :fildname token (key) part of the string
+ * and then converts the next token (value) to the correct data type.
+ *
+ * pg_strtok will split the passed string by whitespace, skipping whitespace in
+ * strings. We do not setup pg_strtok. That is for the the caller to do. By default
+ * that is the responsibility of Postgres' nodeRead function. We assume that was setup
+ * correctly.
+ */
+
+// Read an integer field (anything written as ":fldname %d")
+#define READ_INT_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = atoi(token)
+
+// Read an unsigned integer field (anything written as ":fldname %u")
+#define READ_UINT_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = atoui(token)
+// Read an unsigned integer field (anything written using UINT64_FORMAT)
+#define READ_UINT64_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = pg_strtouint64(token, NULL, 10)
+
+// Read a long integer field (anything written as ":fldname %ld")
+#define READ_LONG_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = atol(token)
+
+// Read an OID field (don't hard-wire assumption that OID is same as uint)
+#define READ_OID_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = atooid(token)
+
+// Read a char field (ie, one ascii character)
+#define READ_CHAR_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        /* avoid overhead of calling debackslash() for one char */ \
+        local_node->fldname = (length == 0) ? '\0' : (token[0] == '\\' ? token[1] : token[0])
+
+// Read an enumerated-type field that was written as an integer code
+#define READ_ENUM_FIELD(fldname, enumtype) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = (enumtype) atoi(token)
+
+// Read a float field
+#define READ_FLOAT_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = atof(token)
+
+// Read a boolean field
+#define READ_BOOL_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = strtobool(token)
+
+// Read a character-string field
+#define READ_STRING_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        local_node->fldname = non_nullable_string(token, length)
+
+// Read a parse location field (and throw away the value, per notes above)
+#define READ_LOCATION_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        token = pg_strtok(&length); \
+        (void) token; \
+        local_node->fldname = -1
+
+// Read a Node field
+#define READ_NODE_FIELD(fldname) \
+        token = pg_strtok(&length);  \
+        (void) token; \
+        local_node->fldname = nodeRead(NULL, 0)
+
+// Read a bitmapset field
+#define READ_BITMAPSET_FIELD(fldname) \
+        token = pg_strtok(&length); \
+        (void) token; \
+        local_node->fldname = _readBitmapset()
+
+// Read an attribute number array
+#define READ_ATTRNUMBER_ARRAY(fldname, len) \
+        token = pg_strtok(&length); \
+        local_node->fldname = readAttrNumberCols(len);
+
+// Read an oid array
+#define READ_OID_ARRAY(fldname, len) \
+        token = pg_strtok(&length); \
+        local_node->fldname = readOidCols(len);
+
+// Read an int array
+#define READ_INT_ARRAY(fldname, len) \
+        token = pg_strtok(&length); \
+        local_node->fldname = readIntCols(len);
+
+// Read a bool array
+#define READ_BOOL_ARRAY(fldname, len) \
+        token = pg_strtok(&length); \
+        local_node->fldname = readBoolCols(len);
+
+/*
+ * NOTE: use atoi() to read values written with %d, or atoui() to read
+ * values written with %u in outfuncs.c.  An exception is OID values,
+ * for which use atooid().  (As of 7.1, outfuncs.c writes OIDs as %u,
+ * but this will probably change in the future.)
+ */
+#define atoui(x)  ((unsigned int) strtoul((x), NULL, 10))
+
+#define strtobool(x)  ((*(x) == 't') ? true : false)
+
+#define nullable_string(token,length)  \
+        ((length) == 0 ? NULL : debackslash(token, length))
+
+#define non_nullable_string(token,length)  \
+        ((length) == 0 ? "" : debackslash(token, length))
+
+/*
+ * Default read function for cypher nodes. For most nodes, we don't expect
+ * the node to ever be read (deserialized). So throw an error.
+ */
+void read_ag_node(ExtensibleNode *node)
+{
+    ereport(ERROR, (errmsg("unexpected parseNodeString() for ag_node")));
+}
+
+/*
+ * Deserialize a string representing the cypher_create_target_nodes
+ * data structure.
+ */
+void read_cypher_create_target_nodes(struct ExtensibleNode *node)
+{
+    READ_LOCALS(cypher_create_target_nodes);
+
+    READ_NODE_FIELD(paths);
+    READ_INT_FIELD(flags);
+    READ_OID_FIELD(graph_oid);
+}
+
+/*
+ * Deserialize a string representing the cypher_create_path
+ * data structure.
+ */
+void read_cypher_create_path(struct ExtensibleNode *node)
+{
+    READ_LOCALS(cypher_create_path);
+
+    READ_NODE_FIELD(target_nodes);
+    READ_INT_FIELD(tuple_position);
+}
+
+/*
+ * Deserialize a string representing the cypher_target_node
+ * data structure.
+ */
+void read_cypher_target_node(struct ExtensibleNode *node)
+{
+    READ_LOCALS(cypher_target_node);
+
+    READ_CHAR_FIELD(type);
+    READ_INT_FIELD(flags);
+    READ_ENUM_FIELD(dir, cypher_rel_dir);
+    READ_INT_FIELD(id_var_no);
+    READ_INT_FIELD(prop_var_no);
+    READ_NODE_FIELD(targetList);
+    READ_NODE_FIELD(te);
+    READ_NODE_FIELD(expr_states);
+    READ_NODE_FIELD(resultRelInfo);
+    READ_NODE_FIELD(elemTupleSlot);
+    READ_OID_FIELD(relid);
+    READ_STRING_FIELD(label_name);
+    READ_STRING_FIELD(variable_name);
+    READ_INT_FIELD(tuple_position);
+}
+
+/*
+ * Deserialize a string representing the cypher_update_information
+ * data structure.
+ */
+void read_cypher_update_information(struct ExtensibleNode *node)
+{
+    READ_LOCALS(cypher_update_information);
+
+    READ_NODE_FIELD(set_items);
+    READ_INT_FIELD(flags);
+    READ_INT_FIELD(tuple_position);
+    READ_STRING_FIELD(graph_name);
+    READ_STRING_FIELD(clause_name);
+}
+
+/*
+ * Deserialize a string representing the cypher_update_item
+ * data structure.
+ */
+void read_cypher_update_item(struct ExtensibleNode *node)
+{
+    READ_LOCALS(cypher_update_item);
+
+    READ_INT_FIELD(prop_position);
+    READ_INT_FIELD(entity_position);
+    READ_STRING_FIELD(var_name);
+    READ_STRING_FIELD(prop_name);
+    READ_NODE_FIELD(qualified_name);
+    READ_BOOL_FIELD(remove_item);
+}
+
+/*
+ * Deserialize a string representing the cypher_delete_information
+ * data structure.
+ */
+void read_cypher_delete_information(struct ExtensibleNode *node)
+{
+    READ_LOCALS(cypher_delete_information);
+
+    READ_NODE_FIELD(delete_items);
+    READ_INT_FIELD(flags);
+    READ_STRING_FIELD(graph_name);
+    READ_OID_FIELD(graph_oid);
+    READ_BOOL_FIELD(detach);
+}
+
+/*
+ * Deserialize a string representing the cypher_delete_item
+ * data structure.
+ */
+void read_cypher_delete_item(struct ExtensibleNode *node)
+{
+    READ_LOCALS(cypher_delete_item);
+
+    READ_NODE_FIELD(entity_position);
+    READ_STRING_FIELD(var_name);
+}
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
deleted file mode 100644
index eb65ce7..0000000
--- a/src/backend/nodes/outfuncs.c
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-#include "postgres.h"
-
-#include "lib/stringinfo.h"
-#include "nodes/extensible.h"
-#include "nodes/nodes.h"
-
-#include "nodes/cypher_nodes.h"
-
-#define DEFINE_AG_NODE(type) \
-    type *_node = (type *)node
-
-#define write_node_field(field_name) \
-    do \
-    { \
-        appendStringInfoString(str, " :" CppAsString(field_name) " "); \
-        outNode(str, _node->field_name); \
-    } while (0)
-
-#define write_string_field(field_name) \
-    do \
-    { \
-        appendStringInfoString(str, " :" CppAsString(field_name) " "); \
-        outToken(str, _node->field_name); \
-    } while (0)
-
-#define write_bool_field(field_name) \
-    do \
-    { \
-        appendStringInfo(str, " :" CppAsString(field_name) " %s", \
-                         _node->field_name ? "true" : "false"); \
-    } while (0)
-
-// write an enumerated-type field as an integer code
-#define write_enum_field(field_name, enum_type) \
-    do \
-    { \
-        appendStringInfo(str, " :" CppAsString(field_name) " %d", \
-                         (int)_node->field_name); \
-    } while (0)
-
-#define write_location_field(field_name) \
-    do \
-    { \
-        appendStringInfo(str, " :" CppAsString(field_name) " %d", \
-                         _node->field_name); \
-    } while (0)
-
-#define write_int64_field(field_name) \
-    do \
-    { \
-        appendStringInfo(str, " :" CppAsString(field_name) " %ld", \
-                         _node->field_name); \
-    } while (0)
-
-/*
- * clauses
- */
-
-void out_cypher_return(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_return);
-
-    write_bool_field(distinct);
-    write_node_field(items);
-    write_node_field(order_by);
-    write_node_field(skip);
-    write_node_field(limit);
-}
-
-void out_cypher_with(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_with);
-
-    write_bool_field(distinct);
-    write_node_field(items);
-    write_node_field(order_by);
-    write_node_field(skip);
-    write_node_field(limit);
-    write_node_field(where);
-}
-
-void out_cypher_match(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_match);
-
-    write_node_field(pattern);
-    write_node_field(where);
-}
-
-void out_cypher_create(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_create);
-
-    write_node_field(pattern);
-}
-
-void out_cypher_set(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_set);
-
-    write_node_field(items);
-    write_bool_field(is_remove);
-}
-
-void out_cypher_set_item(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_set_item);
-
-    write_node_field(prop);
-    write_node_field(expr);
-    write_bool_field(is_add);
-}
-
-void out_cypher_delete(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_delete);
-
-    write_bool_field(detach);
-    write_node_field(exprs);
-}
-
-/*
- * pattern
- */
-
-void out_cypher_path(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_path);
-
-    write_node_field(path);
-    write_location_field(location);
-}
-
-void out_cypher_node(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_node);
-
-    write_string_field(name);
-    write_string_field(label);
-    write_node_field(props);
-    write_location_field(location);
-}
-
-void out_cypher_relationship(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_relationship);
-
-    write_string_field(name);
-    write_string_field(label);
-    write_node_field(props);
-    write_node_field(varlen);
-    write_enum_field(dir, cypher_rel_dir);
-    write_location_field(location);
-}
-
-/*
- * expression
- */
-
-void out_cypher_bool_const(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_bool_const);
-
-    write_bool_field(boolean);
-    write_location_field(location);
-}
-
-void out_cypher_param(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_param);
-
-    write_string_field(name);
-    write_location_field(location);
-}
-
-void out_cypher_map(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_map);
-
-    write_node_field(keyvals);
-    write_location_field(location);
-}
-
-void out_cypher_list(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_list);
-
-    write_node_field(elems);
-    write_location_field(location);
-}
-
-/*
- * string match
- */
-
-void out_cypher_string_match(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_string_match);
-
-    write_enum_field(operation, cypher_string_match_op);
-    write_node_field(lhs);
-    write_node_field(rhs);
-    write_location_field(location);
-}
-
-/* typecast */
-void out_cypher_typecast(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_typecast);
-
-    write_node_field(expr);
-    write_string_field(typecast);
-    write_location_field(location);
-}
-
-/* integer constant */
-void out_cypher_integer_const(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_integer_const);
-
-    write_int64_field(integer);
-    write_location_field(location);
-}
-
-/* sub pattern */
-void out_cypher_sub_pattern(StringInfo str, const ExtensibleNode *node)
-{
-    DEFINE_AG_NODE(cypher_sub_pattern);
-
-    write_enum_field(kind, csp_kind);
-    write_node_field(pattern);
-}
diff --git a/src/backend/optimizer/cypher_paths.c b/src/backend/optimizer/cypher_paths.c
index 51bd67d..ac353ec 100644
--- a/src/backend/optimizer/cypher_paths.c
+++ b/src/backend/optimizer/cypher_paths.c
@@ -129,15 +129,14 @@ static void handle_cypher_delete_clause(PlannerInfo *root, RelOptInfo *rel,
 {
     TargetEntry *te;
     FuncExpr *fe;
-    Const *c;
     List *custom_private;
     CustomPath *cp;
 
     // Add the pattern to the CustomPath
     te = (TargetEntry *)llast(rte->subquery->targetList);
     fe = (FuncExpr *)te->expr;
-    c = linitial(fe->args);
-    custom_private = list_make1(DatumGetPointer(c->constvalue));
+    // pass the const that holds the data structure to the path.
+    custom_private = fe->args;
 
     cp = create_cypher_delete_path(root, rel, custom_private);
 
@@ -158,15 +157,14 @@ static void handle_cypher_create_clause(PlannerInfo *root, RelOptInfo *rel,
 {
     TargetEntry *te;
     FuncExpr *fe;
-    Const *c;
     List *custom_private;
     CustomPath *cp;
 
     // Add the pattern to the CustomPath
     te = (TargetEntry *)llast(rte->subquery->targetList);
     fe = (FuncExpr *)te->expr;
-    c = linitial(fe->args);
-    custom_private = list_make1(DatumGetPointer(c->constvalue));
+    // pass the const that holds the data structure to the path.
+    custom_private = fe->args;
 
     cp = create_cypher_create_path(root, rel, custom_private);
 
@@ -184,15 +182,14 @@ static void handle_cypher_set_clause(PlannerInfo *root, RelOptInfo *rel,
 {
     TargetEntry *te;
     FuncExpr *fe;
-    Const *c;
     List *custom_private;
     CustomPath *cp;
 
     // Add the pattern to the CustomPath
     te = (TargetEntry *)llast(rte->subquery->targetList);
     fe = (FuncExpr *)te->expr;
-    c = linitial(fe->args);
-    custom_private = list_make1(DatumGetPointer(c->constvalue));
+    // pass the const that holds the data structure to the path.
+    custom_private = fe->args;
 
     cp = create_cypher_set_path(root, rel, custom_private);
 
diff --git a/src/backend/parser/cypher_clause.c b/src/backend/parser/cypher_clause.c
index f49379f..57d9e05 100644
--- a/src/backend/parser/cypher_clause.c
+++ b/src/backend/parser/cypher_clause.c
@@ -324,10 +324,11 @@ static Query *transform_cypher_delete(cypher_parsestate *cpstate,
     Expr *func_expr;
     RangeTblEntry *rte;
     int rtindex;
+    StringInfo str = makeStringInfo();
 
     cypher_delete_information *delete_data;
 
-    delete_data = palloc0(sizeof(cypher_delete_information));
+    delete_data = make_ag_node(cypher_delete_information);
 
     query = makeNode(Query);
     query->commandType = CMD_SELECT;
@@ -358,8 +359,20 @@ static Query *transform_cypher_delete(cypher_parsestate *cpstate,
     if (!clause->next)
         delete_data->flags |= CYPHER_CLAUSE_FLAG_TERMINAL;
 
-    pattern_const = makeConst(INTERNALOID, -1, InvalidOid, 1,
-                              PointerGetDatum(delete_data), false, true);
+    /*
+     * Serialize the cypher_delete_information data structure. In certain
+     * cases (Prepared Statements and PL/pgsql), the MemoryContext that
+     * it is stored in will be destroyed. We need to get it into a format
+     * that Postgres' can copy between MemoryContexts. Just making it into
+     * an ExtensibleNode does not work, because there are certain parts of
+     * Postgres that cannot handle an ExtensibleNode in a function call.
+     * So we serialize the data structure and place it into a Const node
+     * that can handle these situations AND be copied correctly.
+     */
+    outNode(str, delete_data);
+
+    pattern_const = makeConst(INTERNALOID, -1, InvalidOid, str->len,
+                              PointerGetDatum(str->data), false, false);
 
     func_expr = (Expr *)makeFuncExpr(func_set_oid, AGTYPEOID,
                                      list_make1(pattern_const), InvalidOid,
@@ -394,7 +407,7 @@ static List *transform_cypher_delete_item_list(cypher_parsestate *cpstate,
         Value *val, *pos;
         int resno;
 
-        cypher_delete_item *item = palloc(sizeof(cypher_delete_item));
+        cypher_delete_item *item = make_ag_node(cypher_delete_item);
 
         if (!IsA(expr, ColumnRef))
             ereport(ERROR, (errmsg_internal("unexpected Node for cypher_clause")));
@@ -439,6 +452,7 @@ static Query *transform_cypher_set(cypher_parsestate *cpstate,
     Const *pattern_const;
     Expr *func_expr;
     char *clause_name;
+    StringInfo str = makeStringInfo();
 
     query = makeNode(Query);
     query->commandType = CMD_SELECT;
@@ -490,8 +504,20 @@ static Query *transform_cypher_set(cypher_parsestate *cpstate,
     if (!clause->next)
         set_items_target_list->flags |= CYPHER_CLAUSE_FLAG_TERMINAL;
 
-    pattern_const = makeConst(INTERNALOID, -1, InvalidOid, 1,
-                              PointerGetDatum(set_items_target_list), false, true);
+    /*
+     * Serialize the cypher_update_information data structure. In certain
+     * cases (Prepared Statements and PL/pgsql), the MemoryContext that
+     * it is stored in will be destroyed. We need to get it into a format
+     * that Postgres' can copy between MemoryContexts. Just making it into
+     * an ExtensibleNode does not work, because there are certain parts of
+     * Postgres that cannot handle an ExtensibleNode in a function call.
+     * So we serialize the data structure and place it into a Const node
+     * that can handle these situations AND be copied correctly.
+     */
+    outNode(str, set_items_target_list);
+
+    pattern_const = makeConst(INTERNALOID, -1, InvalidOid, str->len,
+                              PointerGetDatum(str->data), false, false);
 
     func_expr = (Expr *)makeFuncExpr(func_set_oid, AGTYPEOID,
                                      list_make1(pattern_const), InvalidOid,
@@ -513,7 +539,7 @@ cypher_update_information *transform_cypher_remove_item_list(
 {
     ParseState *pstate = (ParseState *)cpstate;
     ListCell *li;
-    cypher_update_information *info = palloc0(sizeof(cypher_update_information));
+    cypher_update_information *info = make_ag_node(cypher_update_information);
 
     info->set_items = NIL;
     info->flags = 0;
@@ -527,7 +553,7 @@ cypher_update_information *transform_cypher_remove_item_list(
         char *variable_name, *property_name;
         Value *property_node, *variable_node;
 
-        item = palloc0(sizeof(cypher_update_item));
+        item = make_ag_node(cypher_update_item);
 
         if (!is_ag_node(lfirst(li), cypher_set_item))
             ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -596,7 +622,7 @@ cypher_update_information *transform_cypher_set_item_list(
 {
     ParseState *pstate = (ParseState *)cpstate;
     ListCell *li;
-    cypher_update_information *info = palloc0(sizeof(cypher_update_information));
+    cypher_update_information *info = make_ag_node(cypher_update_information);
 
     info->set_items = NIL;
     info->flags = 0;
@@ -611,7 +637,7 @@ cypher_update_information *transform_cypher_set_item_list(
         char *variable_name, *property_name;
         Value *property_node, *variable_node;
 
-        item = palloc0(sizeof(cypher_update_item));
+        item = make_ag_node(cypher_update_item);
 
         if (!is_ag_node(lfirst(li), cypher_set_item))
             ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -2390,8 +2416,9 @@ static Query *transform_cypher_create(cypher_parsestate *cpstate,
     Oid func_create_oid;
     Query *query;
     TargetEntry *tle;
+    StringInfo str = makeStringInfo();
 
-    target_nodes = palloc(sizeof(cypher_create_target_nodes));
+    target_nodes = make_ag_node(cypher_create_target_nodes);
     target_nodes->flags = CYPHER_CLAUSE_FLAG_NONE;
     target_nodes->graph_oid = cpstate->graph_oid;
 
@@ -2433,8 +2460,20 @@ static Query *transform_cypher_create(cypher_parsestate *cpstate,
         target_nodes->flags |= CYPHER_CLAUSE_FLAG_TERMINAL;
     }
 
-    pattern_const = makeConst(INTERNALOID, -1, InvalidOid, 1,
-                              PointerGetDatum(target_nodes), false, true);
+    /*
+     * Serialize the cypher_create_target_nodes data structure. In certain
+     * cases (Prepared Statements and PL/pgsql), the MemoryContext that
+     * it is stored in will be destroyed. We need to get it into a format
+     * that Postgres' can copy between MemoryContexts. Just making it into
+     * an ExtensibleNode does not work, because there are certain parts of
+     * Postgres that cannot handle an ExtensibleNode in a function call.
+     * So we serialize the data structure and place it into a Const node
+     * that can handle these situations AND be copied correctly.
+     */
+    outNode(str, target_nodes);
+
+    pattern_const = makeConst(INTERNALOID, -1, InvalidOid, str->len,
+                              PointerGetDatum(str->data), false, false);
 
     /*
      * Create the FuncExpr Node.
@@ -2483,7 +2522,7 @@ transform_cypher_create_path(cypher_parsestate *cpstate, List **target_list,
     ParseState *pstate = (ParseState *)cpstate;
     ListCell *lc;
     List *transformed_path = NIL;
-    cypher_create_path *ccp = palloc(sizeof(cypher_create_path));
+    cypher_create_path *ccp = make_ag_node(cypher_create_path);
     bool in_path = path->var_name != NULL;
 
     foreach (lc, path->path)
@@ -2564,7 +2603,7 @@ transform_create_cypher_edge(cypher_parsestate *cpstate, List **target_list,
                              cypher_relationship *edge)
 {
     ParseState *pstate = (ParseState *)cpstate;
-    cypher_target_node *rel = palloc(sizeof(cypher_target_node));
+    cypher_target_node *rel = make_ag_node(cypher_target_node);
     List *targetList = NIL;
     Expr *id, *props;
     Relation label_relation;
@@ -2766,7 +2805,7 @@ static cypher_target_node *transform_create_cypher_existing_node(
     cypher_node *node)
 {
     ParseState *pstate = (ParseState *)cpstate;
-    cypher_target_node *rel = palloc(sizeof(cypher_target_node));
+    cypher_target_node *rel = make_ag_node(cypher_target_node);
     char *alias;
     int resno;
     RangeTblEntry *rte = find_rte(cpstate, PREV_CYPHER_CLAUSE_ALIAS);
@@ -2840,7 +2879,7 @@ transform_create_cypher_new_node(cypher_parsestate *cpstate,
                                  List **target_list, cypher_node *node)
 {
     ParseState *pstate = (ParseState *)cpstate;
-    cypher_target_node *rel = palloc(sizeof(cypher_target_node));
+    cypher_target_node *rel = make_ag_node(cypher_target_node);
     Node *id;
     Relation label_relation;
     RangeVar *rv;
diff --git a/src/include/nodes/ag_nodes.h b/src/include/nodes/ag_nodes.h
index 83d7e2c..a44e26d 100644
--- a/src/include/nodes/ag_nodes.h
+++ b/src/include/nodes/ag_nodes.h
@@ -56,7 +56,17 @@ typedef enum ag_node_tag
     // integer constant
     cypher_integer_const_t,
     // sub patterns
-    cypher_sub_pattern_t
+    cypher_sub_pattern_t,
+    // create data structures
+    cypher_create_target_nodes_t,
+    cypher_create_path_t,
+    cypher_target_node_t,
+    // set/remove data structures
+    cypher_update_information_t,
+    cypher_update_item_t,
+    // delete data structures
+    cypher_delete_information_t,
+    cypher_delete_item_t
 } ag_node_tag;
 
 void register_ag_nodes(void);
diff --git a/src/include/nodes/cypher_copyfuncs.h b/src/include/nodes/cypher_copyfuncs.h
new file mode 100644
index 0000000..d55c12f
--- /dev/null
+++ b/src/include/nodes/cypher_copyfuncs.h
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef AG_CYPHER_COPYFUNCS_H
+#define AG_CYPHER_COPYFUNCS_H
+
+#include "postgres.h"
+
+#include "nodes/nodes.h"
+
+/*
+ * Functions that let AGE's ExtensibleNodes be compatible with
+ * Postgres' copyObject. We assign each node to its copy function
+ * in the DEFINE_NODE_METHODS and DEFINE_NODE_METHODS_EXTENDED
+ * macros in ag_nodes.c
+ */
+
+void copy_ag_node(ExtensibleNode *newnode,
+                         const ExtensibleNode *oldnode);
+
+// create data structures
+void copy_cypher_create_target_nodes(ExtensibleNode *newnode, const ExtensibleNode *from);
+void copy_cypher_create_path(ExtensibleNode *newnode, const ExtensibleNode *from);
+void copy_cypher_target_node(ExtensibleNode *newnode, const ExtensibleNode *from);
+
+// set/remove data structures
+void copy_cypher_update_information(ExtensibleNode *newnode, const ExtensibleNode *from);
+void copy_cypher_update_item(ExtensibleNode *newnode, const ExtensibleNode *from);
+
+// delete data structures
+void copy_cypher_delete_information(ExtensibleNode *newnode, const ExtensibleNode *from);
+void copy_cypher_delete_item(ExtensibleNode *newnode, const ExtensibleNode *from);
+
+#endif
diff --git a/src/include/nodes/cypher_nodes.h b/src/include/nodes/cypher_nodes.h
index 99b7860..6deaa77 100644
--- a/src/include/nodes/cypher_nodes.h
+++ b/src/include/nodes/cypher_nodes.h
@@ -204,6 +204,7 @@ typedef struct cypher_string_match
 
 typedef struct cypher_create_target_nodes
 {
+    ExtensibleNode extensible;
     List *paths;
     uint32 flags;
     Oid graph_oid;
@@ -211,6 +212,7 @@ typedef struct cypher_create_target_nodes
 
 typedef struct cypher_create_path
 {
+    ExtensibleNode extensible;
     List *target_nodes;
     AttrNumber tuple_position;
 } cypher_create_path;
@@ -225,22 +227,23 @@ typedef struct cypher_create_path
 #define CYPHER_CLAUSE_HAS_PREVIOUS_CLAUSE(flags) \
     (flags & CYPHER_CLAUSE_FLAG_PREVIOUS_CLAUSE)
 
- typedef struct cypher_target_node
- {
-     char type;
-     uint32 flags;
-     cypher_rel_dir dir;
-     int id_var_no;
-     int prop_var_no;
-     List *targetList;
-     TargetEntry *te;
-     List *expr_states;
-     ResultRelInfo *resultRelInfo;
-     TupleTableSlot *elemTupleSlot;
-     Oid relid;
-     char *label_name;
-     char *variable_name;
-     AttrNumber tuple_position;
+typedef struct cypher_target_node
+{
+    ExtensibleNode extensible;
+    char type;
+    uint32 flags;
+    cypher_rel_dir dir;
+    int id_var_no;
+    int prop_var_no;
+    List *targetList;
+    TargetEntry *te;
+    List *expr_states;
+    ResultRelInfo *resultRelInfo;
+    TupleTableSlot *elemTupleSlot;
+    Oid relid;
+    char *label_name;
+    char *variable_name;
+    AttrNumber tuple_position;
 } cypher_target_node;
 
 #define CYPHER_TARGET_NODE_FLAG_NONE 0x0000
@@ -280,6 +283,7 @@ typedef struct cypher_create_path
 /* Data Structures that contain information about a vertices and edges the need to be updated */
 typedef struct cypher_update_information
 {
+    ExtensibleNode extensible;
     List *set_items;
     int flags;
     AttrNumber tuple_position;
@@ -289,6 +293,7 @@ typedef struct cypher_update_information
 
 typedef struct cypher_update_item
 {
+    ExtensibleNode extensible;
     AttrNumber prop_position;
     AttrNumber entity_position;
     char *var_name;
@@ -299,6 +304,7 @@ typedef struct cypher_update_item
 
 typedef struct cypher_delete_information
 {
+    ExtensibleNode extensible;
     List *delete_items;
     int flags;
     char *graph_name;
@@ -308,6 +314,7 @@ typedef struct cypher_delete_information
 
 typedef struct cypher_delete_item
 {
+    ExtensibleNode extensible;
     Value *entity_position;
     char *var_name;
 } cypher_delete_item;
@@ -321,36 +328,4 @@ typedef struct cypher_typecast
     int location;
 } cypher_typecast;
 
-/* clauses */
-void out_cypher_return(StringInfo str, const ExtensibleNode *node);
-void out_cypher_with(StringInfo str, const ExtensibleNode *node);
-void out_cypher_match(StringInfo str, const ExtensibleNode *node);
-void out_cypher_create(StringInfo str, const ExtensibleNode *node);
-void out_cypher_set(StringInfo str, const ExtensibleNode *node);
-void out_cypher_set_item(StringInfo str, const ExtensibleNode *node);
-void out_cypher_delete(StringInfo str, const ExtensibleNode *node);
-
-/* pattern */
-void out_cypher_path(StringInfo str, const ExtensibleNode *node);
-void out_cypher_node(StringInfo str, const ExtensibleNode *node);
-void out_cypher_relationship(StringInfo str, const ExtensibleNode *node);
-
-/* expression */
-void out_cypher_bool_const(StringInfo str, const ExtensibleNode *node);
-void out_cypher_param(StringInfo str, const ExtensibleNode *node);
-void out_cypher_map(StringInfo str, const ExtensibleNode *node);
-void out_cypher_list(StringInfo str, const ExtensibleNode *node);
-
-/* string match */
-void out_cypher_string_match(StringInfo str, const ExtensibleNode *node);
-
-/* typecast */
-void out_cypher_typecast(StringInfo str, const ExtensibleNode *node);
-
-/* integer constant */
-void out_cypher_integer_const(StringInfo str, const ExtensibleNode *node);
-
-/* sub pattern */
-void out_cypher_sub_pattern(StringInfo str, const ExtensibleNode *node);
-
 #endif
diff --git a/src/include/nodes/cypher_outfuncs.h b/src/include/nodes/cypher_outfuncs.h
new file mode 100644
index 0000000..8a555f4
--- /dev/null
+++ b/src/include/nodes/cypher_outfuncs.h
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef AG_CYPHER_OUTFUNCS_H
+#define AG_CYPHER_OUTFUNCS_H
+
+#include "postgres.h"
+
+#include "nodes/extensible.h"
+#include "nodes/nodes.h"
+
+/*
+ * Serialization functions for AGE's ExtensibleNodes. We assign
+ * each node to its serialized function in the DEFINE_NODE_METHODS
+ * and DEFINE_NODE_METHODS_EXTENDED macros in ag_nodes.c.
+ */
+
+// clauses
+void out_cypher_return(StringInfo str, const ExtensibleNode *node);
+void out_cypher_with(StringInfo str, const ExtensibleNode *node);
+void out_cypher_match(StringInfo str, const ExtensibleNode *node);
+void out_cypher_create(StringInfo str, const ExtensibleNode *node);
+void out_cypher_set(StringInfo str, const ExtensibleNode *node);
+void out_cypher_set_item(StringInfo str, const ExtensibleNode *node);
+void out_cypher_delete(StringInfo str, const ExtensibleNode *node);
+
+// pattern
+void out_cypher_path(StringInfo str, const ExtensibleNode *node);
+void out_cypher_node(StringInfo str, const ExtensibleNode *node);
+void out_cypher_relationship(StringInfo str, const ExtensibleNode *node);
+
+// expression
+void out_cypher_bool_const(StringInfo str, const ExtensibleNode *node);
+void out_cypher_param(StringInfo str, const ExtensibleNode *node);
+void out_cypher_map(StringInfo str, const ExtensibleNode *node);
+void out_cypher_list(StringInfo str, const ExtensibleNode *node);
+
+// string match
+void out_cypher_string_match(StringInfo str, const ExtensibleNode *node);
+
+// typecast
+void out_cypher_typecast(StringInfo str, const ExtensibleNode *node);
+
+// integer constant
+void out_cypher_integer_const(StringInfo str, const ExtensibleNode *node);
+
+// sub pattern
+void out_cypher_sub_pattern(StringInfo str, const ExtensibleNode *node);
+
+// create private data structures
+void out_cypher_create_target_nodes(StringInfo str, const ExtensibleNode *node);
+void out_cypher_create_path(StringInfo str, const ExtensibleNode *node);
+void out_cypher_target_node(StringInfo str, const ExtensibleNode *node);
+
+// set/remove private data structures
+void out_cypher_update_information(StringInfo str, const ExtensibleNode *node);
+void out_cypher_update_item(StringInfo str, const ExtensibleNode *node);
+
+// delete private data structures
+void out_cypher_delete_information(StringInfo str, const ExtensibleNode *node);
+void out_cypher_delete_item(StringInfo str, const ExtensibleNode *node);
+
+#endif
diff --git a/src/include/nodes/cypher_readfuncs.h b/src/include/nodes/cypher_readfuncs.h
new file mode 100644
index 0000000..65637fa
--- /dev/null
+++ b/src/include/nodes/cypher_readfuncs.h
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef AG_CYPHER_READFUNCS_H
+#define AG_CYPHER_READFUNCS_H
+
+#include "postgres.h"
+
+#include "nodes/extensible.h"
+#include "nodes/nodes.h"
+
+/*
+ * Deserialization functions for AGE's ExtensibleNodes. We assign
+ * each node to its deserialization functionin the DEFINE_NODE_METHODS
+ * and DEFINE_NODE_METHODS_EXTENDED macros in ag_nodes.c.
+
+ *
+ * All functions are dependent on the pg_strtok function. We do not
+ * setup pg_strtok. That is for the the caller to do. By default that
+ * is the responsibility of Postgres' nodeRead function. We assume
+ * that was setup correctly.
+ */
+
+void read_ag_node(ExtensibleNode *node);
+
+// create data structures
+void read_cypher_create_target_nodes(struct ExtensibleNode *node);
+void read_cypher_create_path(struct ExtensibleNode *node);
+void read_cypher_target_node(struct ExtensibleNode *node);
+
+// set/remove data structures
+void read_cypher_update_information(struct ExtensibleNode *node);
+void read_cypher_update_item(struct ExtensibleNode *node);
+
+// delete data structures
+void read_cypher_delete_information(struct ExtensibleNode *node);
+void read_cypher_delete_item(struct ExtensibleNode *node);
+
+#endif