byteamagic
Detect MIME types and file formats from PostgreSQL bytea values
Repository
nmandery/pg_byteamagic
https://github.com/nmandery/pg_byteamagic
Source
pg_byteamagic-0.2.4.tar.gz
pg_byteamagic-0.2.4.tar.gz
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_byteamagic | 0.2.4 | UTIL | BSD 2-Clause | C |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 4275 | byteamagic | No | Yes | No | Yes | No | Yes | - |
Extension name is byteamagic; package name is pg_byteamagic.
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.2.4 | 1817161514 | pg_byteamagic | - |
| RPM | PIGSTY | 0.2.4 | 1817161514 | pg_byteamagic_$v | - |
| DEB | PIGSTY | 0.2.4 | 1817161514 | postgresql-$v-pg-byteamagic | - |
Build
You can build the RPM / DEB packages for pg_byteamagic using pig build:
pig build pkg pg_byteamagic # build RPM / DEB packages
Install
You can install pg_byteamagic directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
pig repo add pgsql -u # Add repo and update cache
Install the extension using pig or apt/yum/dnf:
pig install pg_byteamagic; # Install for current active PG version
pig ext install -y pg_byteamagic -v 18 # PG 18
pig ext install -y pg_byteamagic -v 17 # PG 17
pig ext install -y pg_byteamagic -v 16 # PG 16
pig ext install -y pg_byteamagic -v 15 # PG 15
pig ext install -y pg_byteamagic -v 14 # PG 14
dnf install -y pg_byteamagic_18 # PG 18
dnf install -y pg_byteamagic_17 # PG 17
dnf install -y pg_byteamagic_16 # PG 16
dnf install -y pg_byteamagic_15 # PG 15
dnf install -y pg_byteamagic_14 # PG 14
apt install -y postgresql-18-pg-byteamagic # PG 18
apt install -y postgresql-17-pg-byteamagic # PG 17
apt install -y postgresql-16-pg-byteamagic # PG 16
apt install -y postgresql-15-pg-byteamagic # PG 15
apt install -y postgresql-14-pg-byteamagic # PG 14
Create Extension:
CREATE EXTENSION byteamagic;
Usage
Sources: official repo, official doc
byteamagic runs libmagic on bytea values, so PostgreSQL can identify the MIME type or human-readable file type of blobs stored in the database. The package name is pg_byteamagic, but the extension name is byteamagic.
CREATE EXTENSION byteamagic;
SELECT byteamagic_mime(data) FROM files;
SELECT byteamagic_text(data) FROM files;
Functions
byteamagic_mime(bytea) returns text: MIME type, equivalent tofile --mime-type.byteamagic_text(bytea) returns text: descriptive file type text, equivalent tofile.
Common Use
SELECT
id,
byteamagic_mime(blob) AS mime,
byteamagic_text(blob) AS kind
FROM uploads;
Caveats
- It only inspects
byteacontent; there are no operators, custom types, or extra SQL management objects. - Build/install requires PostgreSQL development headers plus the system
libmagicdevelopment package. - The upstream documentation is minimal; current user-facing behavior is unchanged from the long-standing doc page.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.