Skip to content

media_types

Strongly typed MIME media-type data type for PostgreSQL

emi_monorepo · Strongly typed MIME media-type data type for PostgreSQL

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100810media_typesemi_monorepo0.1.0TYPEGPL-3.0Rust

PostgreSQL · 13, 14, 15, 16, 17

Usage

Sources:

media_types adds the MediaType type for validated media-type strings such as image/gif. It is useful when content metadata should be parsed and constrained instead of stored as unchecked text.

Core Workflow

CREATE EXTENSION media_types;

CREATE TABLE assets (
    path text PRIMARY KEY,
    content_type MediaType NOT NULL
);

INSERT INTO assets VALUES ('logo.gif', 'image/gif');
SELECT * FROM assets WHERE content_type = 'image/gif'::MediaType;

The parser checks the root type and subtype against the registry embedded in the build and preserves optional parameters. Unknown combinations are rejected.

SQL Objects

  • MediaType is a variable-length type whose PGRX binary protocol uses CBOR serialization in this release.
  • Comparison operators =, <>, <, <=, >, and >= are available.
  • MediaType_btree_ops and MediaType_hash_ops support B-tree and hash indexes.

Operational Notes

Version 0.1.0 is non-relocatable. Its control file sets superuser = true and trusted = false, so a superuser must create it; it declares no prerequisite extension or preload requirement. The accepted subtype registry is compiled into the extension. Upstream retains some deprecated media types with guidance toward replacements, so application validation and extension upgrades should be reviewed together.

Table reader