1

AGE has a custom data type called agtype, which, according to AGE's documentation, it is the only data type returned by AGE and it contains data like the JSON format. Vertices and Edges are store as follows:

-- Vertex
{id:1; label: 'label_name'; properties: {prop1: value1, prop2: value2}}::vertex

-- Edge
{id: 3; startid: 1; endid: 2; label: 'edge_label' properties{prop1: value1, prop2: value2}}::edge

But other data types are not outputted like this. For example, path, map, and numeric, when returned, are followed only by a ::type whilst bool, integer, and float are showed in the commonly used way.

If I wanted to create a new custom data type for AGE, what should be the necessary changes in the code? Which files and/or structures would it need to be modified? Should it follow the way that vertices and edges are made, like in the JSON format, or should it be different?

Matheus Farias
  • 716
  • 1
  • 10

1 Answers1

2

I guess you need to have a look into two places starting from the script of age--version.sql we need to identify that for example here is ag_type definition in the script:

CREATE TYPE agtype (
  INPUT = ag_catalog.agtype_in,
  OUTPUT = ag_catalog.agtype_out,
  SEND = ag_catalog.agtype_send,
  RECEIVE = ag_catalog.agtype_recv,
  LIKE = jsonb
);

What are the in, out, send and recv types?


CREATE FUNCTION ag_catalog.agtype_in(cstring)
RETURNS agtype
LANGUAGE c
STABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog.agtype_out(agtype)
RETURNS cstring
LANGUAGE c
STABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';


-- binary I/O functions
CREATE FUNCTION ag_catalog.agtype_send(agtype)
RETURNS bytea
LANGUAGE c
IMMUTABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

CREATE FUNCTION ag_catalog.agtype_recv(internal)
RETURNS agtype
LANGUAGE c
IMMUTABLE
RETURNS NULL ON NULL INPUT
PARALLEL SAFE
AS 'MODULE_PATHNAME';

that recalls why when we make an integer with ag_type we send it as a string for example.

And then the agtype.c file and the adt directory

References: