invantive documentationpart of invantive cloud
Invantive Support ForumsLog In / Sign Up

NEWID

Syntax

%%{init: {
  'theme': 'base',
  'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
  'themeVariables': {
    'fontSize': '11px',
    'fontFamily': 'Arial'
  }
}}%%
flowchart LR
    Start((START)) --> NEWID[NEWID]:::quoted
    NEWID --> End((END))

Purpose

The NEWID SQL function creates a new GUID ID.

The ID is random, of UUID version 4, and betrays nothing about when it was made. PostgreSQL 18 names the same function uuidv4 and gen_random_uuid, and both names work here too; see UUIDV4 and GEN_RANDOM_UUID. Use UUIDV7 for an ID from which the time of creation can be read.

Returns: the new GUID ID.

Examples

The following example creates a new GUID. The actual value differs per invocation:

select newid()

------------------------------------
0e984725-c51c-4bf4-9960-e1c80e27aba0

The following example creates a new GUID for each of three rows. The actual values differ per invocation:

select newid() from range@DataDictionary(3)

------------------------------------
78d8da4a-2102-4f0c-8d5b-70a20cf05be9
0e984725-c51c-4bf4-9960-e1c80e27aba0
64a54ac5-fb36-4e5c-b721-64e6e69b4d63