---
title: "PostgreSQL 固有のデータベース関数"
version: 5.1
locale: ja
source: https://docs.djangoproject.com/ja/5.1/ref/contrib/postgres/functions/
canonical: https://djangodocs.dev/ja/5.1/ref/contrib/postgres/functions/
---
# PostgreSQL 固有のデータベース関数

これらの関数はすべて `django.contrib.postgres.functions` モジュールから利用できます。

## `RandomUUID`

#### `class RandomUUID`

バージョン 4 の UUID を返します。

PostgreSQL \< 13 では、 [pgcrypto extension](https://www.postgresql.org/docs/current/pgcrypto.html) をインストールする必要があります。 [`CryptoExtension`](/ja/5.1/ref/contrib/postgres/operations/#django.contrib.postgres.operations.CryptoExtension) マイグレーションオペレーションを使ってインストールできます。

使用例:

```pycon
>>> from django.contrib.postgres.functions import RandomUUID
>>> Article.objects.update(uuid=RandomUUID())
```

## `TransactionNow`

#### `class TransactionNow`

現在のトランザクションが開始されたデータベースサーバー上の日時を返します。トランザクション中でない場合は、現在のステートメントの日時を返します。これは [`django.db.models.functions.Now`](/ja/5.1/ref/models/database-functions/#django.db.models.functions.Now) を補完するもので、現在のステートメントの日時を返します。

[`atomic()`](/ja/5.1/topics/db/transactions/#django.db.transaction.atomic) への最も外側の呼び出しのみがトランザクションを設定され、 `TransactionNow()` が返す時間を設定することに注意してください。ネストされた呼び出しはセーブポイントを作成しますが、トランザクションの時間には影響しません。

使用例:

```pycon
>>> from django.contrib.postgres.functions import TransactionNow
>>> Article.objects.filter(published__lte=TransactionNow())
<QuerySet [<Article: How to Django>]>
```
