> ## Documentation Index
> Fetch the complete documentation index at: https://docs-relytone.data.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# uuid-ossp

> Generate and manage Universally Unique Identifiers (UUIDs) in Relyt ONE.

The **uuid-ossp** extension provides functions to generate universally unique identifiers (UUIDs) using one of several standard algorithms. It is useful for creating unique primary keys that are unique across distributed systems.

For more information, see the official [PostgreSQL uuid-ossp Documentation](https://www.postgresql.org/docs/current/uuid-ossp.html).

## Quick Start

### Step 1: Enable Extension

Enable the extension in your database:

```sql theme={null}
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
```

### Step 2: Generate UUIDs

Generate a random Version 4 UUID (most common):

```sql theme={null}
SELECT uuid_generate_v4();
```

**Expected Output:**

```
           uuid_generate_v4           
--------------------------------------
 a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
```

Generate a Version 1 UUID (timestamp & MAC address):

```sql theme={null}
SELECT uuid_generate_v1();
```

### Step 3: Use as Primary Key

Create a table using UUID as the primary key with a default value:

```sql theme={null}
CREATE TABLE users (
    user_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
    username VARCHAR(50),
    email VARCHAR(100)
);

INSERT INTO users (username, email) VALUES
    ('john_doe', 'john@example.com'),
    ('jane_smith', 'jane@example.com');

SELECT * FROM users;
```

## Functions

| Function                            | Return Type | Description                                                                                  |
| :---------------------------------- | :---------- | :------------------------------------------------------------------------------------------- |
| `uuid_generate_v1()`                | `uuid`      | Generates a version 1 UUID using MAC address and timestamp.                                  |
| `uuid_generate_v1mc()`              | `uuid`      | Generates a version 1 UUID using a random multicast MAC address.                             |
| `uuid_generate_v3(namespace, name)` | `uuid`      | Generates a deterministic version 3 UUID (MD5) from namespace and name.                      |
| `uuid_generate_v4()`                | `uuid`      | Generates a random version 4 UUID.                                                           |
| `uuid_generate_v5(namespace, name)` | `uuid`      | Generates a deterministic version 5 UUID (SHA-1) from namespace and name. Preferred over v3. |
