---
title: "SQL DDL to Protobuf"
description: "Turn a Postgres CREATE TABLE statement into a proto3 message from your AI assistant."
slug: "sql-to-protobuf"
type: recipe
locale: en-US
canonical: "https://www.coremodels.io/recipe/converter/sql-to-protobuf"
updatedAt: "2026-12-03T06:32:53+00:00"
last_updated: "2026-12-03T06:32:53+00:00"
---

# SQL DDL to Protobuf

Turn a Postgres CREATE TABLE statement into a proto3 message from your AI assistant.

You have a Postgres table. You need a proto3 message. Use this when a gRPC service must serve the rows of a table. The output keeps the column names, the descriptions and the CHECK values, and marks the nullable column as optional. The page shows the recorded output and lists what did not carry over.

- Tool: `transform_schema` on https://go.coremodels.io/mcp (read-only, sign-in required)
- From: PostgreSQL DDL
- To: Protobuf
- Recorded: 2026-12-03

## What you get

A proto3 message with seven numbered fields and an enum for `status`. This is the answer CoreModels gave on 3 December 2026 for the file below.

`order.proto`

```protobuf
syntax = "proto3";

// A purchase order placed by a customer.
message orders {
  // Order number printed on the receipt.
  string order_id = 1;
  // The customer who placed the order.
  string customer_id = 2;
  // Where the order is now.
  ordersStatusEnum status = 3;
  // Order total, tax included.
  double total_amount = 4;
  // ISO 4217 currency code.
  string currency = 5;
  // When the customer placed the order.
  string placed_at = 6;
  // Code used at checkout, if any.
  optional string discount_code = 7;
}

enum ordersStatusEnum {
  placed = 0;
  shipped = 1;
  delivered = 2;
  returned = 3;
}
```

## What you need

- A CoreModels account with one project. Every plan starts with a 14-day free trial; a card is required to start.
- The tool uses the project only to check your access. It writes nothing.
- An assistant that speaks MCP, such as Claude Code, Claude Desktop or Cursor.
- A PostgreSQL DDL file.

## Run it

### 1. Connect your assistant

In Claude Code, run this command. Then sign in when it asks.

```bash
claude mcp add --transport http coremodels https://go.coremodels.io/mcp
```

Cursor, Claude Desktop and other clients: [connect guide](/mcp-server).

### 2. Save the file as `order.sql`

Use your own file, or start with this one.

`order.sql`

```sql
-- Flat shop order (PostgreSQL)

CREATE TABLE orders (
  order_id       text           NOT NULL,
  customer_id    text           NOT NULL,
  status         text           NOT NULL,
  total_amount   numeric(12, 2) NOT NULL,
  currency       text           NOT NULL,
  placed_at      timestamptz    NOT NULL,
  discount_code  text,
  CONSTRAINT orders_pkey PRIMARY KEY (order_id),
  CONSTRAINT orders_status_chk
    CHECK (status IN ('placed', 'shipped', 'delivered', 'returned'))
);

COMMENT ON TABLE  orders IS 'A purchase order placed by a customer.';
COMMENT ON COLUMN orders.order_id IS 'Order number printed on the receipt.';
COMMENT ON COLUMN orders.customer_id IS 'The customer who placed the order.';
COMMENT ON COLUMN orders.status IS 'Where the order is now.';
COMMENT ON COLUMN orders.total_amount IS 'Order total, tax included.';
COMMENT ON COLUMN orders.currency IS 'ISO 4217 currency code.';
COMMENT ON COLUMN orders.placed_at IS 'When the customer placed the order.';
COMMENT ON COLUMN orders.discount_code IS 'Code used at checkout, if any.';
```

### 3. Ask for the conversion

```text
Use the CoreModels transform_schema tool to convert order.sql from sql to protobuf. Pass the whole file as sourceSchema. Use any project from list_projects. Save the result as order.proto, then list every entry in lossiness.
```

Your assistant calls `transform_schema` with these arguments.

`transform_schema`

```json
{
  "graphProjectId": "<your project id>",
  "sourceFormat": "sql",
  "sourceSchema": "<contents of order.sql>",
  "targetFormat": "protobuf"
}
```

## What did not carry over

- We tested one table. Several tables with foreign keys are not tested on this page.

CoreModels reported these changes with the answer:

- `Element[ordersPlacedAt]`: proto3 has no date-time scalar; DateTime degrades to string.
- `Element[ordersOrderId]`: protobuf has no primary key; that 'order_id' is in the primary key was dropped.
- `Element[ordersTotalAmount]`: protobuf cannot hold decimal(12,2); it became the nearest type.

We compared the two files ourselves and also found:

- The default value. In proto3 a missing `status` reads as `placed`, because it is value 0.
- Required fields. Proto3 has no required rule, so the six required fields become plain fields.

Compare your own files too. A different file can lose other things.

## Check it yourself

Compile the file with protoc.

```bash
pip install grpcio-tools
python -m grpc_tools.protoc -I. --descriptor_set_out=order.desc order.proto
```

## Same file, other formats

- [PostgreSQL DDL to JSON Schema](/recipe/converter/sql-to-jsonschema)
- [PostgreSQL DDL to Avro](/recipe/converter/sql-to-avro)
- [PostgreSQL DDL to ODCS v3 data contract](/recipe/converter/sql-to-odcs)

[Start building](https://www.coremodels.io/start)

14-day free trial. Builder $49/mo after the trial. Cancel any time.

## Sitemap

- [Sitemap in markdown](https://www.coremodels.io/sitemap.md)
