@@ -499,25 +499,25 @@ SELECT * FROM cypher('cypher_create', $$
499
499
CREATE (a {test:1})-[:e_var]->()
500
500
$$) as (a agtype);
501
501
ERROR: previously declared nodes in a create clause cannot have properties
502
- LINE 1: SELECT * FROM cypher('cypher_create', $$
503
- ^
502
+ LINE 4: CREATE (a {test:1})-[:e_var]->()
503
+ ^
504
504
-- Var 'a' cannot change labels
505
505
SELECT * FROM cypher('cypher_create', $$
506
506
MATCH (a:n_var)
507
507
WHERE a.name = 'Node A'
508
508
CREATE (a:new_label)-[:e_var]->()
509
509
$$) as (a agtype);
510
510
ERROR: previously declared variables cannot have a label
511
- LINE 1: SELECT * FROM cypher('cypher_create', $$
512
- ^
511
+ LINE 4: CREATE (a:new_label)-[:e_var]->()
512
+ ^
513
513
SELECT * FROM cypher('cypher_create', $$
514
514
MATCH (a:n_var)-[b]-()
515
515
WHERE a.name = 'Node A'
516
516
CREATE (a)-[b:e_var]->()
517
517
$$) as (a agtype);
518
518
ERROR: variable b already exists
519
- LINE 1: SELECT * FROM cypher('cypher_create', $$
520
- ^
519
+ LINE 4: CREATE (a)-[b:e_var]->()
520
+ ^
521
521
-- A valid single vertex path
522
522
SELECT * FROM cypher('cypher_create', $$
523
523
CREATE p=(a)
@@ -578,7 +578,7 @@ SELECT * FROM cypher('cypher_create', $$
578
578
$$) as (a agtype);
579
579
ERROR: label existing_elabel is for edges, not vertices
580
580
LINE 2: CREATE (a:existing_elabel { id: 5})
581
- ^
581
+ ^
582
582
--
583
583
-- check the cypher CREATE clause inside an INSERT INTO
584
584
--
@@ -641,12 +641,137 @@ SELECT * FROM cypher('cypher_create', $$ MATCH (a:Part) RETURN a $$) as (a agtyp
641
641
642
642
END;
643
643
--
644
+ -- variable reuse
645
+ --
646
+ -- Valid variable reuse
647
+ SELECT * FROM cypher('cypher_create', $$
648
+ CREATE (p)-[a:new]->(p)
649
+ RETURN p,a,p
650
+ $$) as (n1 agtype, e agtype, n2 agtype);
651
+ n1 | e | n2
652
+ ----------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------
653
+ {"id": 281474976710681, "label": "", "properties": {}}::vertex | {"id": 3940649673949185, "label": "new", "end_id": 281474976710681, "start_id": 281474976710681, "properties": {}}::edge | {"id": 281474976710681, "label": "", "properties": {}}::vertex
654
+ (1 row)
655
+
656
+ SELECT * FROM cypher('cypher_create', $$
657
+ CREATE (p:node)-[e:new]->(p)
658
+ RETURN p,e,p
659
+ $$) as (n1 agtype, e agtype, n2 agtype);
660
+ n1 | e | n2
661
+ ---------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------
662
+ {"id": 4222124650659841, "label": "node", "properties": {}}::vertex | {"id": 3940649673949186, "label": "new", "end_id": 4222124650659841, "start_id": 4222124650659841, "properties": {}}::edge | {"id": 4222124650659841, "label": "node", "properties": {}}::vertex
663
+ (1 row)
664
+
665
+ SELECT * FROM cypher('cypher_create', $$
666
+ CREATE (p)
667
+ CREATE (p)-[a:new]->(p)
668
+ RETURN p,a,p
669
+ $$) as (n1 agtype, e agtype, n2 agtype);
670
+ n1 | e | n2
671
+ ----------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------+----------------------------------------------------------------
672
+ {"id": 281474976710682, "label": "", "properties": {}}::vertex | {"id": 3940649673949187, "label": "new", "end_id": 281474976710682, "start_id": 281474976710682, "properties": {}}::edge | {"id": 281474976710682, "label": "", "properties": {}}::vertex
673
+ (1 row)
674
+
675
+ SELECT * FROM cypher('cypher_create', $$
676
+ CREATE (p:n1)
677
+ CREATE (p)-[a:new]->(p)
678
+ RETURN p,a,p
679
+ $$) as (n1 agtype, e agtype, n2 agtype);
680
+ n1 | e | n2
681
+ -------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+-------------------------------------------------------------------
682
+ {"id": 4503599627370497, "label": "n1", "properties": {}}::vertex | {"id": 3940649673949188, "label": "new", "end_id": 4503599627370497, "start_id": 4503599627370497, "properties": {}}::edge | {"id": 4503599627370497, "label": "n1", "properties": {}}::vertex
683
+ (1 row)
684
+
685
+ SELECT * FROM cypher('cypher_create', $$
686
+ MATCH (p:node)
687
+ CREATE (p)-[a:new]->(p)
688
+ RETURN p,a,p
689
+ $$) as (n1 agtype, e agtype, n2 agtype);
690
+ n1 | e | n2
691
+ ---------------------------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------+---------------------------------------------------------------------
692
+ {"id": 4222124650659841, "label": "node", "properties": {}}::vertex | {"id": 3940649673949189, "label": "new", "end_id": 4222124650659841, "start_id": 4222124650659841, "properties": {}}::edge | {"id": 4222124650659841, "label": "node", "properties": {}}::vertex
693
+ (1 row)
694
+
695
+ -- Invalid variable reuse
696
+ SELECT * FROM cypher('cypher_create', $$
697
+ CREATE (p)-[a:new]->(p {n0:'n1'})
698
+ $$) as (a agtype);
699
+ ERROR: previously declared nodes in a create clause cannot have properties
700
+ LINE 2: CREATE (p)-[a:new]->(p {n0:'n1'})
701
+ ^
702
+ SELECT * FROM cypher('cypher_create', $$
703
+ CREATE (p:n0)-[a:new]->(p:n1)
704
+ $$) as (a agtype);
705
+ ERROR: previously declared variables cannot have a label
706
+ LINE 2: CREATE (p:n0)-[a:new]->(p:n1)
707
+ ^
708
+ SELECT * FROM cypher('cypher_create', $$
709
+ CREATE p=(p)
710
+ $$) as (a agtype);
711
+ ERROR: variable "p" already exists
712
+ LINE 2: CREATE p=(p)
713
+ ^
714
+ SELECT * FROM cypher('cypher_create', $$
715
+ CREATE p=() CREATE (p)
716
+ $$) as (a agtype);
717
+ ERROR: agtype must resolve to a vertex
718
+ SELECT * FROM cypher('cypher_create', $$
719
+ CREATE p=(a)-[p:b]->(a)
720
+ $$) as (a agtype);
721
+ ERROR: variable "p" already exists
722
+ LINE 2: CREATE p=(a)-[p:b]->(a)
723
+ ^
724
+ SELECT * FROM cypher('cypher_create', $$
725
+ CREATE p=(a)-[:new]->(p)
726
+ $$) as (a agtype);
727
+ ERROR: variable "p" already exists
728
+ LINE 2: CREATE p=(a)-[:new]->(p)
729
+ ^
730
+ SELECT * FROM cypher('cypher_create', $$
731
+ MATCH (p) CREATE p=()
732
+ $$) as (a agtype);
733
+ ERROR: variable "p" already exists
734
+ LINE 2: MATCH (p) CREATE p=()
735
+ ^
736
+ SELECT * FROM cypher('cypher_create', $$
737
+ MATCH (p) CREATE p=(p)
738
+ $$) as (a agtype);
739
+ ERROR: variable "p" already exists
740
+ LINE 2: MATCH (p) CREATE p=(p)
741
+ ^
742
+ SELECT * FROM cypher('cypher_create', $$
743
+ MATCH (p) CREATE (a)-[p:b]->(a)
744
+ $$) as (a agtype);
745
+ ERROR: variable p already exists
746
+ LINE 2: MATCH (p) CREATE (a)-[p:b]->(a)
747
+ ^
748
+ SELECT * FROM cypher('cypher_create', $$
749
+ CREATE (a)-[e:new]->(p)-[e]->(a)
750
+ $$) as (a agtype);
751
+ ERROR: relationships must be specify a label in CREATE.
752
+ LINE 2: CREATE (a)-[e:new]->(p)-[e]->(a)
753
+ ^
754
+ SELECT * FROM cypher('cypher_create', $$
755
+ CREATE (a)-[e:new]->(p)
756
+ CREATE (p)-[e:new]->(a)
757
+ $$) as (a agtype);
758
+ ERROR: variable e already exists
759
+ LINE 3: CREATE (p)-[e:new]->(a)
760
+ ^
761
+ SELECT * FROM cypher('cypher_create', $$
762
+ MATCH (a)-[e:new]->(p)
763
+ CREATE (p)-[e:new]->(a)
764
+ $$) as (a agtype);
765
+ ERROR: variable e already exists
766
+ LINE 3: CREATE (p)-[e:new]->(a)
767
+ ^
768
+ --
644
769
-- Clean up
645
770
--
646
771
DROP TABLE simple_path;
647
772
DROP FUNCTION create_test;
648
773
SELECT drop_graph('cypher_create', true);
649
- NOTICE: drop cascades to 13 other objects
774
+ NOTICE: drop cascades to 16 other objects
650
775
DETAIL: drop cascades to table cypher_create._ag_label_vertex
651
776
drop cascades to table cypher_create._ag_label_edge
652
777
drop cascades to table cypher_create.v
@@ -660,6 +785,9 @@ drop cascades to table cypher_create.existing_vlabel
660
785
drop cascades to table cypher_create.existing_elabel
661
786
drop cascades to table cypher_create.knows
662
787
drop cascades to table cypher_create."Part"
788
+ drop cascades to table cypher_create.new
789
+ drop cascades to table cypher_create.node
790
+ drop cascades to table cypher_create.n1
663
791
NOTICE: graph "cypher_create" has been dropped
664
792
drop_graph
665
793
------------
0 commit comments