Updated on 2024-08-20 GMT+08:00

UUID Functions

  • sys_guid()

    Description: Generates and returns a 16-byte universally unique identifier (UUID). The generated UUID contains the IP address of the current node, generation timestamp, and random number.

    Parameter: none

    Return type: raw

    Example:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    gaussdb=# SET a_format_version='10c';
    SET
    gaussdb=# SET a_format_dev_version='s5';
    SET
    gaussdb=# SELECT sys_guid();
                 sys_guid             
    ----------------------------------
     9010675E560CB33C1BDAFA163E378F87
     (1 row)
    
  • uuid()

    Description: Returns a UUID defined in RFC 4122, ISO/IEF 9834-8:2005, and related standards. The identifier is a string of lowercase hexadecimal digits, which are divided into several groups: a group of 8 digits, three groups of 4 digits, and a group of 12 digits. A total of 32 digits represent 128 bits.

    Parameter: none

    Return type: varchar

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT uuid();
                     uuid                 
    --------------------------------------
     dd8cbe92-1a25-013c-a514-e435c87e9182
    (1 row)
    
  • uuid_short()

    Description: Returns a short UUID under certain conditions. This identifier is a 64-bit unsigned integer.

    The returned value is unique when the following conditions are met:

    • The number of service nodes in the current cluster cannot exceed 256.
    • You cannot set the system time of the server host between node restarts.
    • The average number of uuid_short() calls per second between node restarts is less than 16 million.

    Parameter: none

    Return type: uint64

    Example:

    1
    2
    3
    4
    5
    gaussdb=# SELECT uuid_short();
         uuid_short     
    --------------------
     100440026956955649
    (1 row)
    

    For upgrade from a version to GaussDB Kernel 505.0.0, the uuid_short() function cannot be used if the upgrade is not committed.