Method and apparatus for creating custom data types

By redesigning the syntax and functionality in the PostgreSQL database, creating member attributes and functions, the problem of PostgreSQL's inability to create member functions was solved, compatibility with Oracle database was achieved, and the migration efficiency of custom data types and database compatibility were improved.

CN114297195BActive Publication Date: 2025-11-21HIGHGO SOFTWARE
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111601416.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2025-11-21
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

PostgreSQL databases cannot create member functions, and their syntax differs significantly from Oracle databases, making seamless compatibility during migration impossible and limiting the application and migration efficiency of custom data types.

Method used

By redesigning the syntax and functionality in the PostgreSQL database, the creation of member attributes and member functions is implemented, including inserting data into the pg_type, pg_class, and pg_attribute tables, creating member function headers and function bodies, updating the oid in the pg_namespace table, and supporting the replace function to update or replace existing types.

Benefits of technology

It achieves compatibility and ease of use between PostgreSQL and Oracle databases, improves the efficiency of application migration for custom data types, and enhances database compatibility and product competitiveness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114297195B_ABST
    Figure CN114297195B_ABST
Patent Text Reader

Abstract

The application provides a method and device for creating a custom data type, which comprises the following steps: S100, creating a custom data type header, including creating a member attribute and creating a member function header; S200, creating a custom type function body, including: judging whether the data type exists, if not, reporting an error; if yes, judging whether the function body exists, if not, creating the function body; if yes, judging whether to replace, if not, reporting an error, if yes, updating the function body. On the basis of the original function, the syntax and function are redesigned, and both the syntax for creating a custom data type by using postgresql and the syntax for creating a custom data type by using oracle can be compatible. The compatibility of the database is greatly improved, and the product competitiveness is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of database, in particular to a method and device for creating a custom data type. BACKGROUND

[0002] The custom data type is a data type created by a user, which includes member attributes and member functions, the member attributes are variables defined in the custom data type, and the member functions include a constructor function, a member / static function, a member / static procedure, a map / order member function, and each function and procedure has a different meaning in the custom data type.

[0003] In the postgresql database, a custom data type is created by using

create type name as (attribute1, attribute2,...)

[0004] In the oracle database, a custom data type header is created by using

create type name as object (attribute1, attribute2,..., member function,...)

create type body name as member function... end;

[0005] In the postgresql database, the original custom data type syntax only supports the creation of member attributes, does not support the creation of member functions, and has a large difference in the creation syntax from the oracle database, and seamless migration from the oracle database to the postgresql database cannot be realized. SUMMARY

[0006] The present application aims to solve the compatibility of the postgresql database syntax and function to the oracle, enhance the compatibility and ease of use of the postgresql, and improve the application migration efficiency, and provides a method and device for creating a custom data type.

[0007] The method for creating a custom data type according to the present application embodiment comprises the following steps.

[0008] S100, a custom data type header is created, including creating member attributes and creating a member function header;

[0009] S200, creating a custom type function body, comprising:

[0010] judging whether the data type exists, if not, reporting an error, if yes, judging whether the function body exists, if not, creating the function body, if yes, judging whether to replace, if not, reporting an error, if yes, updating the function body.

[0011] According to some embodiments of the present application, in step S100, the creating of the member attribute specifically comprises:

[0012] S111, inserting corresponding data in the pg_type table, the pg_class table and the pg_attribute table according to the custom data type;

[0013] S112, obtaining the oid of the custom data type in the pg_type table, obtaining the type name and the type mode, and creating a pseudo mode same as the type name and the type mode in the pg_namespace table;

[0014] S113, judging whether there is a member function header, if not, ending, if yes, creating the member function header.

[0015] In some embodiments of the present application, in step S100, the creating of the member function header specifically comprises:

[0016] S121, obtaining the pseudo mode same as the type name and the type mode from the pg_namespace, and defining the promemberkind value for the member function header;

[0017] S122, performing a function creating process, and inserting corresponding data in the pg_proc table;

[0018] S123, obtaining the oid of the function from the data structure returned after the creating of the function header, and updating the oid to the nspobjecthead field of the pg_namespace table.

[0019] According to some embodiments of the present application, in step S200, the judging of whether the function body exists comprises:

[0020] S211, obtaining the nspobjecthead field value from the pg_namespace table according to the type name and the type mode of the custom data type;

[0021] S212, judging whether the member function is declared in the created type header, if not, reporting an error, if yes, updating or creating the function body.

[0022] In some embodiments of the present application, the method for creating the function body comprises:

[0023] S221, filling the prosrc field value in the pg_proc table;

[0024] S222, obtaining the oid of the function from the returned data structure and updating the nspobjectbody field in the pg_namespace table.

[0025] According to some embodiments of the present application, the method further comprises:

[0026] When creating the custom data type, it is judged whether the custom data type exists, if not, step S100 is executed, if yes, it is judged whether the replace function is performed, if not, an error is reported, if yes, the custom data type is updated.

[0027] In some embodiments of the present application, updating the custom data type comprises:

[0028] Updating the member attribute, including updating the corresponding data in the pg_type table, the pg_class table and the pg_attribute table;

[0029] Updating the member function header, including:

[0030] Judging whether the custom data type member function header is the same as the original member function header, if yes, ending; if not, removing the original member function and creating a new member function header, updating the nspobjecthead field in the pg_namespace table.

[0031] The device for creating the custom data type according to the embodiments of the present application comprises:

[0032] The first creating module is used for creating the custom data type header, including creating the member attribute and creating the member function header;

[0033] The second creating module is used for creating the custom type function body, including:

[0034] Judging whether the data type exists, if not, an error is reported; if yes, judging whether the function body exists, if not, creating the function body; if yes, judging whether the replace function is performed, if not, an error is reported, if yes, updating the function body.

[0035] According to some embodiments of the present application, the device further comprises:

[0036] A judging module is configured to judge whether the custom data type exists when the custom data type is created, and if not, create a custom data type header through the first creating module;

[0037] An updating module is configured to update the custom data type when it is judged that the custom data type exists and the replace function is performed.

[0038] In some embodiments of the present application, the updating module comprises:

[0039] An attribute updating module is configured to update the member attribute, including updating the corresponding data in the pg_type table, the pg_class table and the pg_attribute table.

[0040] A function updating module is configured to update the member function header, including:

[0041] Judging whether the custom data type member function header is the same as the original member function header, if yes, ending; if not, removing the original member function and creating a new member function header, and updating the nspobjecthead field of the pg_namespace table.

[0042] The method and device for creating a custom data type have the following advantages:

[0043] On the basis of the original function, the syntax and function are redesigned, and both the syntax for creating a custom data type using postgresql and the syntax for creating a custom data type using oracle can be compatible. The compatibility of the database is greatly improved, and the product competitiveness is improved. BRIEF DESCRIPTION OF DRAWINGS

[0044] Figure 1 It is a schematic diagram of the inter-table association relationship of the database system according to the embodiment of the present application.

[0045] Figure 2 It is a method flow chart of creating a custom data type header in the method for creating a custom data type according to the embodiment of the present application.

[0046] Figure 3 It is a method flow chart of creating a custom data type function body in the method for creating a custom data type according to the embodiment of the present application.

[0047] Figure 4 It is a schematic diagram of the composition of the device for creating a custom data type according to the embodiment of the present application.

[0048] Reference signs:

[0049] Device 100,

[0050] The first creating module 10, the second creating module 20, the judging module 30 and the updating module 40. DETAILED DESCRIPTION

[0051] In order to further clarify the technical means and effects taken by the present application to achieve the predetermined purpose, the present application is described in detail as follows in combination with the drawings and preferred embodiments.

[0052] The description of the method flow in the specification of the present application and the steps of the flow chart in the drawings of the present application are not necessarily strictly executed according to the step numbers. The method steps can change the execution order. Moreover, some steps can be omitted, a plurality of steps can be combined into one step for execution, and / or one step can be divided into a plurality of steps for execution.

[0053] The related terms involved in the present application are explained as follows:

[0054] Schema: that is, a namespace, which contains command objects (tables, data types, functions and operators, etc.). When creating these objects, the prefix added in front of the object is the schema.

[0055] Oid: object identifier, which is unique in the database and is identified by an unsigned integer number. This full-database unique unsigned integer number is also called oid.

[0056] For the postgresql database, there are corresponding system tables to store metadata. Each system table represents different meanings and stores different metadata. The association between the system tables is as shown in Figure 1 .

[0057] System table design:

[0058] pg_namespace increases the field:

[0059] Field Explanation nspparentspace Schema corresponding to custom data type nspobjectoid Oid of custom data type nspobjecthead Oid of member function in custom data type header nspobjectbody Oid after implementing member function of custom data type

[0060] pg_proc increases the field:

[0061] Field Explanation promemberkind Type of member function of custom data type

[0062] As shown in Figure 2 and Figure 3 , the method for creating a custom data type according to the embodiment of the present application comprises:

[0063] S100, creating a custom data type header, including creating a member attribute and creating a member function header;

[0064] S200, creating a custom type function body, comprising:

[0065] Judge whether the data type exists, if not, error is reported, if yes, judge whether the function body exists, if not, create the function body, if yes, judge whether to replace, if not, error is reported, if yes, update the function body.

[0066] According to some embodiments of the present application, in combination with Figure 2 As shown in the figure, in step S100, the creating member attribute specifically includes:

[0067] S111, according to the custom data type, insert corresponding data in pg_type table, pg_class table and pg_attribute table;

[0068] S112, get the oid of the custom data type in pg_type table, get the type name and type mode, create the same pseudo mode as the type name and type mode in pg_namespace table;

[0069] S113, judge whether there is a member function header, if not, end, if yes, create the member function header.

[0070] In some embodiments of the present application, in combination with Figure 2 As shown in the figure, in step S100, the creating member function header specifically includes:

[0071] S121, get the same pseudo mode as the type name and type mode from pg_namespace, define promemberkind value for the member function header;

[0072] S122, perform function creation process, insert corresponding data in pg_proc table;

[0073] S123, get the oid of the function from the data structure returned after creating the function header, update the oid to nspobjecthead field in pg_namespace table.

[0074] According to some embodiments of the present application, in combination with Figure 3 As shown in the figure, in step S200, the judging whether the function body exists includes:

[0075] S211, get nspobjecthead field value from pg_namespace table according to the type name and type mode of the custom data type;

[0076] S212, judge whether the member function is declared in the created type header, if not, prompt error, if yes, update or create the function body.

[0077] In some embodiments of the present application, in combination with Figure 3As shown, the function body creation method includes:

[0078] S221, filling the prosrc field value in the pg_proc table;

[0079] S222, obtaining the oid of the function from the returned data structure, and updating the nspobjectbody field in the pg_namespace table.

[0080] According to some embodiments of the present application, in combination with Figure 2 As shown, the method further includes:

[0081] In creating the custom data type, it is judged whether the custom data type exists, if not, step S100 is executed, if yes, it is judged whether to perform the replace function, if not, an error is reported, if yes, the custom data type is updated.

[0082] In some embodiments of the present application, in combination with Figure 2 As shown, updating the custom data type includes:

[0083] Updating the member attribute, including updating the corresponding data in the pg_type table, the pg_class table and the pg_attribute table;

[0084] Updating the member function head, including:

[0085] Judging whether the custom data type member function head is the same as the original member function head, if yes, ending; if not, removing the original member function and creating a new member function head, updating the nspobjecthead field in the pg_namespace table.

[0086] The device 100 for creating a custom data type according to the embodiment of the present application includes a first creation module 10 and a second creation module 20.

[0087] The first creation module 10 is used to create a custom data type head, including creating a member attribute and creating a member function head;

[0088] The second creation module 20 is used to create a custom type function body, including:

[0089] Judging whether the data type exists, if not, an error is reported; if yes, judging whether the function body exists, if not, creating the function body; if yes, judging whether to replace the function, if not, an error is reported, if yes, updating the function body.

[0090] According to some embodiments of the present application, the device 100 further includes a judging module 30 and an updating module 40.

[0091] The judging module 30 is configured to judge whether the custom data type exists when the custom data type is created, and if not, create the custom data type header through the first creating module 10.

[0092] The updating module 40 is configured to update the custom data type when it is judged that the custom data type exists and the replace function is performed.

[0093] In some embodiments of the present application, the updating module 40 comprises:

[0094] The attribute updating module is configured to update the member attribute, including updating the corresponding data in the pg_type table, the pg_class table and the pg_attribute table.

[0095] The function updating module is configured to update the member function header, including:

[0096] Judging whether the custom data type member function header is the same as the original member function header, if yes, ending, if not, removing the original member function and creating a new member function header, and updating the nspobjecthead field of the pg_namespace table.

[0097] The method and device 100 for creating the custom data type have the following advantages:

[0098] The present application re-designs the syntax and function on the basis of the original function, and is compatible with the syntax for creating the custom data type using the postgresql or the syntax for creating the custom data type using the oracle. The compatibility of the database is greatly improved, and the product competitiveness is improved.

[0099] The method and device 100 for creating the custom data type according to the present application will be described in detail below with reference to the accompanying drawings. It should be understood that the following description is only exemplary and should not be construed as specific limitation of the present application.

[0100] When the custom data type is created, it includes:

[0101] Creating the information related to the type in the pg_type, pg_class, pg_attribute system table.

[0102] Creating the schema with the same name as the type in the pg_namespace system table.

[0103] Creating the member function of the custom type in the pg_proc system table.

[0104] For example, Figure 2 and Figure 3As shown, creating a custom data type is divided into two parts, the first part creates the custom data type header, and the second part creates the custom type function body.

[0105] The first part of creating the custom data type header method is as follows:

[0106] Syntax: create [or replace] type name as object (attribute1, attribute2,..., member function,...)

[0107] The flow is as shown. Figure 2

[0108] Creating a custom data type header is divided into two points, the first point creates member attributes, and the second point creates member function headers.

[0109] Determine whether the type already exists, no: create a new type, yes: whether to replace the function, no, error, yes, update the type.

[0110] In creating a new type, creating member attributes includes:

[0111] The system provides a creation mechanism to insert a data into the pg_type table, and the table creation process is followed to insert corresponding data into pg_class and pg_attribute.

[0112] Get the oid of the type in the pg_type table, get the type name and type pattern, and create a pseudo pattern in the pg_namespace table.

[0113] Determine whether there is a member function header, if not, end, if yes, start creating the member function header.

[0114] In creating a new type, creating member function headers includes:

[0115] Get the same pseudo pattern as the type name and type pattern from pg_namespace, define promemberkind value for different member function headers, follow the function creation process, and insert data into pg_proc table. At this time, the prosrc value in the table is empty. Get the oid of the function from the data structure returned after creating the function header, and update the oid to the nspobjecthead field of the pg_namespace table.

[0116] In updating the type, updating the member attributes includes:

[0117] Update the information in the system tables pg_type, pg_class and pg_attribute.

[0118] ​In the update type, the update member function header includes:

[0119] Determine whether the type member function header is the same as the old type member function header. If yes, end. If no, remove the original member function and create a new member function header, update the nspobjecthead field of the pg_namespace table, remove the old function oid and store the new function oid in the field.

[0120] The second part creates a custom type function body, which includes:

[0121] Syntax:

[0122] create [or replace] type body name as

[0123] Function header as

[0124] begin

[0125] pl block

[0126] end; ...

[0128] end;

[0129] Process:

[0130] Determine whether the type exists. If no, report an error. If yes, determine whether the function body exists. If no, create the function body. If yes, determine whether to use the replace function. If no, report an error. If yes, update the function body.

[0131] Updating and creating the function body includes:

[0132] According to the type name and type pattern, get the nspobjecthead field value from the pg_namespace table. Determine whether the member function is declared in the created type header. If not, prompt an error. If yes, go through the function update or creation process, fill in the prosrc field value in the pg_proc table, and after filling, get the function oid from the returned data structure and update the oid to the nspobjectbody field of the pg_namespace table.

[0133] It should be noted that the design of custom data types is an object-oriented design idea, which includes member attributes and member functions. In the postgresql database, only member attributes are implemented, and member function functionality is not implemented, which greatly limits use. If migrating from oracle to postgresql database, the function involving custom data types cannot be successfully migrated, which greatly limits user use.

[0134] The present application re-designs the grammar and functions on the basis of the original functions, and is compatible with the syntax for creating a custom data type using PostgreSQL or the syntax for creating a custom data type using Oracle. The compatibility of the database is greatly improved, and the product competitiveness is improved.

[0135] The technical means and effects taken by the present application to achieve the predetermined purposes can be understood more deeply and specifically through the description of the specific embodiments. However, the accompanying drawings are provided for reference and illustration only, and are not used to limit the present application.

Claims

1. A method for creating a custom data type, comprising: S100, creating a custom data type header, including creating a member attribute and creating a member function header; S200, creating a custom type function body, including: determining whether the data type exists, if not, reporting an error; if yes, determining whether the function body exists, if not, creating the function body; if yes, determining whether to replace, if not, reporting an error, if yes, updating the function body; in step S100, the creating of the member attribute specifically includes: S111, inserting corresponding data in the pg_type table, pg_class table and pg_attribute table according to the custom data type; S112, obtaining the oid of the custom data type in the pg_type table, obtaining the type name and type pattern, and creating a pseudo pattern same as the type name and type pattern in the pg_namespace table; S113, determining whether there is a member function header, if not, ending, if yes, creating the member function header; in step S100, the creating of the member function header specifically includes: S121, obtaining the pseudo pattern same as the type name and type pattern from the pg_namespace, defining the promemberkind value for the member function header; S122, performing a function creation process, inserting corresponding data in the pg_proc table; S123, obtaining the oid of the function from the data structure returned after the creation of the function header, and updating the oid in the nspobjecthead field of the pg_namespace table; wherein, a field of nspparentspace is added in the pg_namespace table, which is used to describe the mode corresponding to the custom data type, a field of nspobjectoid is added, which is used to describe the oid of the custom data type, a field of nspobjecthead is added, which is used to describe the oid of the member function in the custom data type header, a field of nspobjectbody is added, which is used to describe the oid after the implementation of the member function of the custom data type; a field of promemberkind is added in the pg_proc table, which is used to describe the type of the member function of the custom data type.

2. The method of creating a custom data type of claim 1, wherein, in step S200, the determining of whether the function body exists includes: S211, obtaining the value of the nspobjecthead field from the pg_namespace table according to the type name and type pattern of the custom data type; S212, determining whether the member function is declared in the created type header, if not, reporting an error, if yes, updating or creating the function body.

3. The method of creating a custom data type of claim 2, wherein, the method for creating the function body includes: S221, filling the prosrc field value in the pg_proc table; S222, obtaining the oid of the function from the returned data structure, and updating the oid in the nspobjectbody field of the pg_namespace table.

4. The method of creating a custom data type of claim 1, wherein, the method further includes: In creating the custom data type, it is judged whether the custom data type exists, if not, step S100 is executed, if yes, it is judged whether the replace function is performed, if not, an error is reported, if yes, the custom data type is updated.

5. The method of creating a custom data type of claim 4, wherein, The updating of the custom data type comprises: updating the member attribute, including updating the corresponding data in the pg_type table, the pg_class table and the pg_attribute table; updating the member function head, including: judging whether the custom data type member function head is the same as the original member function head, if yes, ending; if not, removing the original member function and creating a new member function head, updating the nspobjecthead field of the pg_namespace table.

6. An apparatus for creating a custom data type, comprising: a first creating module for creating a custom data type head, including creating a member attribute and creating a member function head; a second creating module for creating a custom type function body, including: judging whether the data type exists, if not, reporting an error; if yes, judging whether the function body exists, if not, creating the function body; if yes, judging whether the replace function is performed, if not, reporting an error, if yes, updating the function body; the creating of the member attribute specifically comprises: inserting the corresponding data in the pg_type table, the pg_class table and the pg_attribute table according to the custom data type; obtaining the oid of the custom data type in the pg_type table, obtaining the type name and the type mode, creating the pseudo mode same as the type name and the type mode in the pg_namespace table; judging whether there is a member function head, if not, ending, if yes, creating the member function head; the creating of the member function head specifically comprises: obtaining the pseudo mode same as the type name and the type mode from the pg_namespace, defining the promemberkind value for the member function head; performing the function creating process, inserting the corresponding data in the pg_proc table; obtaining the oid of the function from the data structure returned after the creation of the function head, updating the oid to the nspobjecthead field of the pg_namespace table; wherein, the field of nspparentspace in the pg_namespace table is used for describing the mode corresponding to the custom data type, the field of nspobjectoid is used for describing the oid of the custom data type, the field of nspobjecthead is used for describing the oid of the member function in the custom data type head, the field of nspobjectbody is used for describing the oid after the implementation of the custom data type member function; the field of promemberkind in the pg_proc table is used for describing the type of the custom data type member function.

7. The apparatus for creating a custom data type of claim 6, wherein, The apparatus further comprises: The judging module is configured to judge whether the custom data type exists when the custom data type is created, and if not, create the custom data type header through the first creating module. The updating module is configured to update the custom data type when it is judged that the custom data type exists and the replace function is performed.

8. The apparatus for creating a custom data type of claim 7, wherein, The updating module includes: The attribute updating module is configured to update the member attribute, including updating the corresponding data in the pg_type table, the pg_class table and the pg_attribute table. The function updating module is configured to update the member function header, including: judging whether the custom data type member function header is the same as the original member function header, if yes, ending; if not, removing the original member function and creating a new member function header, and updating the nspobjecthead field of the pg_namespace table.

Citation Information

Patent Citations

  • Supporting user-defined datatypes

    US7092933B1