@@ -253,6 +253,27 @@ static Expr *add_volatile_wrapper(Expr *node) {
253253
254254 return (Expr * )makeFuncExpr (oid , GTYPEOID , list_make1 (node ), InvalidOid , InvalidOid , COERCE_EXPLICIT_CALL );
255255}
256+
257+ static void validate_or_create_vlabel (cypher_parsestate * cpstate , cypher_node * node ) {
258+ ParseState * pstate = (ParseState * )cpstate ;
259+ label_cache_data * lcd = search_label_name_graph_cache (node -> label , cpstate -> graph_oid );
260+
261+ if (lcd && lcd -> kind != LABEL_KIND_VERTEX ) {
262+ ereport (ERROR , (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
263+ errmsg ("label %s is for edges, not vertices" , node -> label ),
264+ parser_errposition (pstate , node -> location )));
265+ } else if (!lcd ) {
266+ List * parent ;
267+ RangeVar * rv ;
268+
269+ rv = get_label_range_var (cpstate -> graph_name , cpstate -> graph_oid , AG_DEFAULT_LABEL_VERTEX );
270+
271+ parent = list_make1 (rv );
272+
273+ create_label (cpstate -> graph_name , node -> label , LABEL_TYPE_VERTEX , parent , NULL );
274+ }
275+ }
276+
256277static Query * transform_cypher_create (cypher_parsestate * cpstate , cypher_clause * clause ) {
257278 ParseState * pstate = (ParseState * )cpstate ;
258279 cypher_create * self = (cypher_create * )clause -> self ;
@@ -291,8 +312,10 @@ static Query *transform_cypher_create(cypher_parsestate *cpstate, cypher_clause
291312
292313 cypher_node * node = (cypher_node * )linitial (path -> path );
293314
294- if (node -> label )
295- ereport (ERROR , (errmsg_internal ("nodes in CREATE cannot have labels" )));
315+ if (node -> label )
316+ validate_or_create_vlabel (cpstate , node );
317+ else
318+ node -> label = AG_DEFAULT_LABEL_VERTEX ;
296319
297320 if (node -> name )
298321 ereport (ERROR , (errmsg_internal ("nodes in CREATE cannot have variable names" )));
@@ -302,10 +325,11 @@ static Query *transform_cypher_create(cypher_parsestate *cpstate, cypher_clause
302325
303326 cypher_target_node * target = make_ag_node (cypher_target_node );
304327
305- label_cache_data * lcd = search_label_name_graph_cache (AG_DEFAULT_LABEL_VERTEX , cpstate -> graph_oid );
328+ label_cache_data * lcd = search_label_name_graph_cache (node -> label , cpstate -> graph_oid );
306329
307330 target -> id_expr = (Expr * )build_column_default (RelationIdGetRelation (lcd -> relation ), 1 );
308-
331+ target -> relid = lcd -> relation ;
332+
309333 TargetEntry * te = makeTargetEntry (make_int_placeholder (cpstate ), pstate -> p_next_resno ++ , make_id_alias (get_next_default_alias (cpstate )), false);
310334
311335 ccp -> target_nodes = list_make1 (target );
0 commit comments