|
| 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=ag_catalog; |
| 21 | +SELECT create_graph('graph'); |
| 22 | +NOTICE: graph "graph" has been created |
| 23 | + create_graph |
| 24 | +-------------- |
| 25 | + |
| 26 | +(1 row) |
| 27 | + |
| 28 | +-- Should error out |
| 29 | +SELECT * FROM cypher('graph', $$ RETURN soundex("hello") $$) AS (n agtype); |
| 30 | +ERROR: function soundex does not exist |
| 31 | +LINE 1: SELECT * FROM cypher('graph', $$ RETURN soundex("hello") $$)... |
| 32 | + ^ |
| 33 | +HINT: If the function is from an external extension, make sure the extension is installed and the function is in the search path. |
| 34 | +-- Create the extension in the public schema |
| 35 | +CREATE EXTENSION fuzzystrmatch SCHEMA public; |
| 36 | +-- Should error out |
| 37 | +SELECT * FROM cypher('graph', $$ RETURN soundex("hello") $$) AS (n agtype); |
| 38 | +ERROR: function soundex does not exist |
| 39 | +LINE 1: SELECT * FROM cypher('graph', $$ RETURN soundex("hello") $$)... |
| 40 | + ^ |
| 41 | +HINT: If the function is from an external extension, make sure the extension is installed and the function is in the search path. |
| 42 | +-- Should work |
| 43 | +SET search_path=ag_catalog, public; |
| 44 | +SELECT * FROM cypher('graph', $$ CREATE (:Person {name: "Jane"}), |
| 45 | + (:Person {name: "John"}), |
| 46 | + (:Person {name: "Jone"}), |
| 47 | + (:Person {name: "Jack"}), |
| 48 | + (:Person {name: "Jax"}), |
| 49 | + (:Person {name: "Jake"}), |
| 50 | + (:Person {name: "Julie"}), |
| 51 | + (:Person {name: "Julius"}), |
| 52 | + (:Person {name: "Jill"}), |
| 53 | + (:Person {name: "Jillie"}), |
| 54 | + (:Person {name: "Julian"}) |
| 55 | +$$) AS (n agtype); |
| 56 | + n |
| 57 | +--- |
| 58 | +(0 rows) |
| 59 | + |
| 60 | +SELECT * FROM cypher('graph', $$ MATCH (p) return soundex(p.name) $$) AS (n agtype); |
| 61 | + n |
| 62 | +-------- |
| 63 | + "J500" |
| 64 | + "J500" |
| 65 | + "J500" |
| 66 | + "J200" |
| 67 | + "J200" |
| 68 | + "J200" |
| 69 | + "J400" |
| 70 | + "J420" |
| 71 | + "J400" |
| 72 | + "J400" |
| 73 | + "J450" |
| 74 | +(11 rows) |
| 75 | + |
| 76 | +SELECT * FROM cypher('graph', $$ MATCH (p) return levenshtein(p.name, "John") $$) AS (n agtype); |
| 77 | + n |
| 78 | +--- |
| 79 | + 3 |
| 80 | + 0 |
| 81 | + 2 |
| 82 | + 3 |
| 83 | + 3 |
| 84 | + 3 |
| 85 | + 4 |
| 86 | + 5 |
| 87 | + 3 |
| 88 | + 5 |
| 89 | + 4 |
| 90 | +(11 rows) |
| 91 | + |
| 92 | +SELECT * FROM cypher('graph', $$ MATCH (p) return difference(p.name, "John") $$) AS (n agtype); |
| 93 | + n |
| 94 | +--- |
| 95 | + 4 |
| 96 | + 4 |
| 97 | + 4 |
| 98 | + 3 |
| 99 | + 3 |
| 100 | + 3 |
| 101 | + 3 |
| 102 | + 2 |
| 103 | + 3 |
| 104 | + 3 |
| 105 | + 2 |
| 106 | +(11 rows) |
| 107 | + |
| 108 | +SELECT * FROM cypher('graph', $$ MATCH (p) return metaphone(p.name, 4) $$) AS (n agtype); |
| 109 | + n |
| 110 | +------- |
| 111 | + "JN" |
| 112 | + "JN" |
| 113 | + "JN" |
| 114 | + "JK" |
| 115 | + "JKS" |
| 116 | + "JK" |
| 117 | + "JL" |
| 118 | + "JLS" |
| 119 | + "JL" |
| 120 | + "JL" |
| 121 | + "JLN" |
| 122 | +(11 rows) |
| 123 | + |
| 124 | +SELECT * FROM cypher('graph', $$ MATCH (p) return dmetaphone(p.name) $$) AS (n agtype); |
| 125 | + n |
| 126 | +------- |
| 127 | + "JN" |
| 128 | + "JN" |
| 129 | + "JN" |
| 130 | + "JK" |
| 131 | + "JKS" |
| 132 | + "JK" |
| 133 | + "JL" |
| 134 | + "JLS" |
| 135 | + "JL" |
| 136 | + "JL" |
| 137 | + "JLN" |
| 138 | +(11 rows) |
| 139 | + |
| 140 | +-- Difference is basically similarity using soundex, https://www.postgresql.org/docs/current/fuzzystrmatch.html |
| 141 | +SELECT * FROM cypher('graph', $$ MATCH (p) return p ORDER BY difference(p.name, "Jon") DESC LIMIT 3$$) AS (n agtype); |
| 142 | + n |
| 143 | +------------------------------------------------------------------------------------ |
| 144 | + {"id": 844424930131970, "label": "Person", "properties": {"name": "John"}}::vertex |
| 145 | + {"id": 844424930131971, "label": "Person", "properties": {"name": "Jone"}}::vertex |
| 146 | + {"id": 844424930131969, "label": "Person", "properties": {"name": "Jane"}}::vertex |
| 147 | +(3 rows) |
| 148 | + |
| 149 | +SELECT * FROM cypher('graph', $$ MATCH (p) return p ORDER BY difference(p.name, "Jak") DESC LIMIT 3$$) AS (n agtype); |
| 150 | + n |
| 151 | +------------------------------------------------------------------------------------ |
| 152 | + {"id": 844424930131972, "label": "Person", "properties": {"name": "Jack"}}::vertex |
| 153 | + {"id": 844424930131973, "label": "Person", "properties": {"name": "Jax"}}::vertex |
| 154 | + {"id": 844424930131974, "label": "Person", "properties": {"name": "Jake"}}::vertex |
| 155 | +(3 rows) |
| 156 | + |
| 157 | +SELECT * FROM cypher('graph', $$ MATCH (p) return p ORDER BY difference(p.name, "Jil") DESC LIMIT 3$$) AS (n agtype); |
| 158 | + n |
| 159 | +-------------------------------------------------------------------------------------- |
| 160 | + {"id": 844424930131975, "label": "Person", "properties": {"name": "Julie"}}::vertex |
| 161 | + {"id": 844424930131977, "label": "Person", "properties": {"name": "Jill"}}::vertex |
| 162 | + {"id": 844424930131978, "label": "Person", "properties": {"name": "Jillie"}}::vertex |
| 163 | +(3 rows) |
| 164 | + |
| 165 | +-- Clean up |
| 166 | +SELECT drop_graph('graph', true); |
| 167 | +NOTICE: drop cascades to 3 other objects |
| 168 | +DETAIL: drop cascades to table graph._ag_label_vertex |
| 169 | +drop cascades to table graph._ag_label_edge |
| 170 | +drop cascades to table graph."Person" |
| 171 | +NOTICE: graph "graph" has been dropped |
| 172 | + drop_graph |
| 173 | +------------ |
| 174 | + |
| 175 | +(1 row) |
| 176 | + |
| 177 | +DROP EXTENSION fuzzystrmatch CASCADE; |
0 commit comments