|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +LOAD 'age'; |
| 20 | +SET search_path TO ag_catalog; |
| 21 | +SELECT create_graph('map_proj'); |
| 22 | +NOTICE: graph "map_proj" has been created |
| 23 | + create_graph |
| 24 | +-------------- |
| 25 | + |
| 26 | +(1 row) |
| 27 | + |
| 28 | +SELECT * FROM cypher('map_proj', |
| 29 | +$$ |
| 30 | + CREATE |
| 31 | + (tom:Actor {name:'Tom Hanks', age:60}), |
| 32 | + (bale:Actor {name:'Christian Bale', age:50}), |
| 33 | + (tom)-[:ACTED_IN {during: 1990}]->(:Movie {title:'Forrest Gump'}), |
| 34 | + (tom)-[:ACTED_IN {during: 1995}]->(:Movie {title:'Finch'}), |
| 35 | + (tom)-[:ACTED_IN {during: 1999}]->(:Movie {title:'The Circle'}), |
| 36 | + (bale)-[:ACTED_IN {during: 2002}]->(:Movie {title:'The Prestige'}), |
| 37 | + (bale)-[:ACTED_IN {during: 2008}]->(:Movie {title:'The Dark Knight'}) |
| 38 | +$$) as (a agtype); |
| 39 | + a |
| 40 | +--- |
| 41 | +(0 rows) |
| 42 | + |
| 43 | +-- all property selection |
| 44 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { .* } $$) as (a agtype); |
| 45 | + a |
| 46 | +---------------------------- |
| 47 | + {"age": 50, "name": "Bob"} |
| 48 | +(1 row) |
| 49 | + |
| 50 | +-- property selector |
| 51 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { .name } $$) as (a agtype); |
| 52 | + a |
| 53 | +----------------- |
| 54 | + {"name": "Bob"} |
| 55 | +(1 row) |
| 56 | + |
| 57 | +-- literal entry |
| 58 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { name:'Tom' } $$) as (a agtype); |
| 59 | + a |
| 60 | +----------------- |
| 61 | + {"name": "Tom"} |
| 62 | +(1 row) |
| 63 | + |
| 64 | +-- variable selector |
| 65 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map, 'Tom' as name RETURN map { name } $$) as (a agtype); |
| 66 | + a |
| 67 | +----------------- |
| 68 | + {"name": "Tom"} |
| 69 | +(1 row) |
| 70 | + |
| 71 | +-- duplicate all property selector |
| 72 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { .*, .* } $$) as (a agtype); |
| 73 | + a |
| 74 | +---------------------------- |
| 75 | + {"age": 50, "name": "Bob"} |
| 76 | +(1 row) |
| 77 | + |
| 78 | +-- name being selected twice |
| 79 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { .name, .* } $$) as (a agtype); |
| 80 | + a |
| 81 | +---------------------------- |
| 82 | + {"age": 50, "name": "Bob"} |
| 83 | +(1 row) |
| 84 | + |
| 85 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { .name, .name } $$) as (a agtype); |
| 86 | + a |
| 87 | +----------------- |
| 88 | + {"name": "Bob"} |
| 89 | +(1 row) |
| 90 | + |
| 91 | +-- name being selected twice with different value |
| 92 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { name:'Tom', .* } $$) as (a agtype); |
| 93 | + a |
| 94 | +---------------------------- |
| 95 | + {"age": 50, "name": "Tom"} |
| 96 | +(1 row) |
| 97 | + |
| 98 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map, 'Tom' as name RETURN map { name, .* } $$) as (a agtype); |
| 99 | + a |
| 100 | +---------------------------- |
| 101 | + {"age": 50, "name": "Tom"} |
| 102 | +(1 row) |
| 103 | + |
| 104 | +-- new entry added |
| 105 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob', age:50} AS map RETURN map { .name, .age, height:180 } $$) as (a agtype); |
| 106 | + a |
| 107 | +------------------------------------------- |
| 108 | + {"age": 50, "name": "Bob", "height": 180} |
| 109 | +(1 row) |
| 110 | + |
| 111 | +-- NULL as a map |
| 112 | +SELECT * FROM cypher('map_proj', $$ WITH NULL AS map RETURN map { .name } $$) as (a agtype); |
| 113 | + a |
| 114 | +---- |
| 115 | + {} |
| 116 | +(1 row) |
| 117 | + |
| 118 | +-- vertex as a map |
| 119 | +SELECT * FROM cypher('map_proj', $$ MATCH (n:Actor) RETURN n { .name } $$) as (a agtype); |
| 120 | + a |
| 121 | +---------------------------- |
| 122 | + {"name": "Tom Hanks"} |
| 123 | + {"name": "Christian Bale"} |
| 124 | +(2 rows) |
| 125 | + |
| 126 | +-- edge as a map |
| 127 | +SELECT * FROM cypher('map_proj', $$ MATCH ()-[e:ACTED_IN]->() RETURN e { .during } $$) as (a agtype); |
| 128 | + a |
| 129 | +------------------ |
| 130 | + {"during": 1990} |
| 131 | + {"during": 1995} |
| 132 | + {"during": 1999} |
| 133 | + {"during": 2002} |
| 134 | + {"during": 2008} |
| 135 | +(5 rows) |
| 136 | + |
| 137 | +-- syntax error |
| 138 | +SELECT * FROM cypher('map_proj', $$ WITH 12 AS map RETURN map { .name } $$) as (a agtype); |
| 139 | +ERROR: properties() argument must be a vertex, an edge or null |
| 140 | +SELECT * FROM cypher('map_proj', $$ WITH [] AS map RETURN map { .name } $$) as (a agtype); |
| 141 | +ERROR: properties() argument must resolve to an object |
| 142 | +SELECT * FROM cypher('map_proj', $$ WITH {name:'Bob'} AS map RETURN map { 'name' } $$) as (a agtype); |
| 143 | +ERROR: syntax error at or near "'name'" |
| 144 | +LINE 1: ...p_proj', $$ WITH {name:'Bob'} AS map RETURN map { 'name' } $... |
| 145 | + ^ |
| 146 | +-- advanced |
| 147 | +SELECT * FROM cypher('map_proj', |
| 148 | +$$ |
| 149 | + MATCH (a:Actor)-[:ACTED_IN]->(m:Movie) |
| 150 | + WITH a, collect(m { .title }) AS movies |
| 151 | + RETURN collect(a { .name, movies }) |
| 152 | +$$) as (a agtype); |
| 153 | + a |
| 154 | +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 155 | + [{"name": "Christian Bale", "movies": [{"title": "The Prestige"}, {"title": "The Dark Knight"}]}, {"name": "Tom Hanks", "movies": [{"title": "Forrest Gump"}, {"title": "Finch"}, {"title": "The Circle"}]}] |
| 156 | +(1 row) |
| 157 | + |
| 158 | +-- drop |
| 159 | +SELECT drop_graph('map_proj', true); |
| 160 | +NOTICE: drop cascades to 5 other objects |
| 161 | +DETAIL: drop cascades to table map_proj._ag_label_vertex |
| 162 | +drop cascades to table map_proj._ag_label_edge |
| 163 | +drop cascades to table map_proj."Actor" |
| 164 | +drop cascades to table map_proj."ACTED_IN" |
| 165 | +drop cascades to table map_proj."Movie" |
| 166 | +NOTICE: graph "map_proj" has been dropped |
| 167 | + drop_graph |
| 168 | +------------ |
| 169 | + |
| 170 | +(1 row) |
| 171 | + |
0 commit comments