Spec & format · target: json schema format to postgres type
OpenAPI to SQL for Format keyword fixture: Full Mapping
User wants format keywords (date-time, uuid, email) mapped to Postgres types.
Direct answer
Converting the Format keyword fixture schema to SQL is a one-to-one mapping for 11 constraints in the DDL, and the foreign key order is the only part that needs reasoning.
The mapping assumes the PostgreSQL dialect, which is the only dialect the CLI emits; a native enum type is not used because it cannot be altered in a transaction.
The mapping table below lists the constructs of Format keyword fixture and their SQL form; the enum row shows the one construct that is written as a CHECK constraint rather than as a native enum type.
Data as of 2026-11-18 · source: 19 Stack Overflow questions, 5 Hacker News stories, json-schema-typed at 352,057,353 monthly downloads · negative-case messages reproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) at 2026-11-18T11:53:54.233Z
The mapping — Format keyword
The table below maps each construct in the Format keyword fixture to what it becomes in SQL. 11 constraints in the DDL all have a SQL equivalent: a primary key per table, a foreign key per reference, a NOT NULL per required column and a CHECK for every enum, range and length declaration. The rows are ordered so the parent table comes first.
The cases that need a decision
One construct needs a decision rather than a translation. On Format keyword fixture, the declaration on events.ip is "ip" ~ '^\d{1,3}(\.\d{1,3}){3}$'. The generator does not create a native enum type, because a native enum has to be created separately and cannot be changed inside a transaction; it writes the declaration as a CHECK constraint on the column instead. The value that breaks the declaration ships as a negative case, and the reference engine rejected it with "CHECK constraint failed: ip NOT LIKE '% %'".
A worked example
The Format keyword fixture is small enough to convert by hand, which is the point. The generator produces 1 tables — events — and each child table is written after the table it references. Doing it by hand for one fixture takes a few minutes; doing it for every schema change after that is the cost this removes.
Type mapping (PostgreSQL only)
SchemaSeed emits one SQL dialect, and it is PostgreSQL. The fixture on this page is written in it: uuid stays uuid, a timestamp becomes timestamptz, and json becomes jsonb, and every constraint is emitted with PostgreSQL semantics. No other database engine is targeted, so the type mapping below is the whole mapping.
Checking the result
A converted schema is worth checking against the database rather than by eye. The reference engine accepted the DDL for all 64 fixtures in this matrix and rejected the deliberately invalid rows with the expected error class each time, which is the check that catches a mistranslated constraint before it reaches a developer database.
| Table | Column | Declared rule | Probe value | Why it is invalid |
|---|---|---|---|---|
| events | ip | dotted quad | 999.1.1.1 x | not an address |
| events | duration_ms | >= 0 | -1 | below the lower bound |
| events | token | length >= 16 | too short | below the minimum length |
| Table | Referenced by | Written |
|---|---|---|
| events | — | first, no dependencies |
| Schema construct | SQL form | Example in this fixture |
|---|---|---|
| object schema | CREATE TABLE events | 7 NOT NULL columns |
| required + foreign key | NOT NULL + FOREIGN KEY REFERENCES | none in this fixture |
| enum | CHECK (col IN (...)) | no enum in this fixture |
| minimum / range | CHECK (col >= n) | ip |
| unique | a plain column; the DDL carries no UNIQUE constraint | no unique column in this fixture |
npx --yes @wenlu8848/schemaseed generate --input ./spec_format.openapi.yaml --out ./seed --formats sql --count 10 --seed 42
Download spec_format.openapi.yaml
-- Generated by schemaseed.
-- seed: 42
-- rows per table: 10
-- Foreign key values are taken from the rows of the referenced table.
BEGIN;
CREATE TABLE IF NOT EXISTS "events" (
"id" UUID,
"occurred_at" TIMESTAMPTZ NOT NULL,
"actor" UUID NOT NULL,
"email" TEXT NOT NULL,
"url" TEXT NOT NULL,
"ip" TEXT NOT NULL,
"duration_ms" INTEGER NOT NULL,
"token" TEXT NOT NULL,
CONSTRAINT "events_pkey" PRIMARY KEY ("id"),
CONSTRAINT "events_ip_check" CHECK ("ip" ~ '^\d{1,3}(\.\d{1,3}){3}$'),
CONSTRAINT "events_duration_ms_check" CHECK ("duration_ms" >= 0),
CONSTRAINT "events_token_check" CHECK (char_length("token") >= 16)
);
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('5ee93434-a1ba-47db-b90b-7c5627b10f8b', '2021-08-16T05:10:35.000Z', '660332ac-25c6-4a8d-bb63-d1b488e8ea49', 'gus.grant494@example.com', 'https://example.com/river/627', '07.184.828.3', 116, 'lumen summit----')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('2c879ff9-6d84-42f2-ab6c-d3cc7ae98ec1', '2023-06-08T18:13:51.000Z', 'a06381e4-977d-42c8-b800-38a781f3a275', 'fay.bianchi34@mail.example', 'https://test.dev/river/788', '8.6.467.7', 520, 'hana.holt@example.com')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('2951920f-6d7c-422e-a45a-0384e431b01e', '2021-10-10T19:40:57.000Z', '80d4dc58-97c8-4d58-b2da-1f60b6ceaeb4', 'bao.grant590@test.dev', 'https://test.dev/zephyr/485', '932.301.85.217', 718, 'Toronto, Riverside Lane 162')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('5e75369e-37af-4d21-8ce7-c8c7572133c3', '2023-10-09T01:22:18.000Z', '12281d90-6fc4-4627-a5ef-edef95a2c5ef', 'lena.novak913@example.com', 'https://example.org/juniper/66', '2.11.56.556', 136, 'juniper meadow--')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('c9c77541-fe0d-4895-8626-d26824ed101d', '2021-05-24T05:31:22.000Z', 'ee21ea83-20d0-4f22-b30c-14e60051a97a', 'kai.lund926@test.dev', 'https://example.net/meadow/470', '01.2.226.2', 982, 'Osaka, Oak Drive 60')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('2b31c031-3497-4b25-873f-743c42fa851d', '2026-08-17T01:58:09.000Z', '808f974a-5ace-49ec-918d-a9d6b4efe46d', 'kai.engel336@test.dev', 'https://test.dev/pebble/693', '483.8.50.055', 801, 'fable-onyx-836--')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('6caaef1c-fc66-43b3-abd4-dc7062d95fe3', '2026-04-24T06:23:23.000Z', '28206fa0-d5bd-4a91-9680-2a0a5d6fabba', 'omar.okafor853@example.net', 'https://test.dev/quartz/628', '9.23.0.5', 759, 'Nairobi, Maple Street 199')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('8549120c-e723-4738-ac0d-6f23b669c544', '2020-10-21T04:32:42.000Z', '5ee34967-15e1-4f5c-a272-385bf53d394b', 'bao.fontaine416@example.org', 'https://mail.example/cedar/238', '796.1.326.2', 56, 'onyx bravo------')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('adc8a932-d23f-4711-81c5-5715785ad92d', '2021-04-11T03:36:32.000Z', '567a72e4-3f30-4227-aba9-3e5bb9450863', 'hana.engel215@example.com', 'https://example.org/tundra/646', '35.2.45.798', 592, 'vertex-juniper-80')
ON CONFLICT DO NOTHING;
INSERT INTO "events" ("id", "occurred_at", "actor", "email", "url", "ip", "duration_ms", "token")
VALUES ('68db92aa-be98-4671-a822-f3585512c6e2', '2020-11-13T10:16:29.000Z', '2b1d0eb4-c98e-44eb-a3e9-4823aab11b80', 'sami.duarte230@test.dev', 'https://test.dev/delta/679', '2.2.032.91', 176, 'kelp zephyr-----')
ON CONFLICT DO NOTHING;
-- (no foreign keys)
COMMIT;
Frequently asked questions
- Is the mapping lossless?
- For Format keyword fixture, 11 constraints in the DDL all have a SQL equivalent, and the mapping table above lists each one with the construct it came from. The enum, range and length declarations become CHECK constraints on the column.
- Why not use a native enum type?
- Because CREATE TYPE runs outside the transaction and cannot be altered while it is open. The CLI does not create an enum type either: it reads the members out of the schema and writes them as a CHECK constraint on the column, so the database refuses a value that is not a member — events.ip on this fixture.
- Does SchemaSeed emit SQL for a database other than PostgreSQL?
- No. The SQL export is PostgreSQL only: uuid, timestamptz and jsonb are the PostgreSQL types and every constraint is emitted with PostgreSQL semantics. The Format keyword fixture was accepted by the reference engine.
- How are foreign keys ordered?
- Topologically, from the reference graph in the schema. For Format keyword fixture the order is events, and the insert-order table lists each parent.
Run it against your own schema
SchemaSeed is MIT licensed and free: unlimited local generation, no account, no telemetry and no usage limit. It reads your schema file on your own machine, so nothing is uploaded anywhere. If it saves you time, you can support the project.
Get SchemaSeed — free Support the project
Questions: support@schemaseed.drz8848.win