Skip to main content
Neon Postgres Docs

Search documentation

Type to search this documentation.

Retrieve database schema

GET/projects/{project_id}/branches/{branch_id}/schemaRetrieve database schema

Retrieves the database schema. Specify lsn or timestamp (not both) to read at a point in time; omit both to read from the database's head.

Parameters

project_idstringpathrequired

The Neon project ID

pattern ^[a-z0-9-]{1,60}$

branch_idstringpathrequired

The branch ID

pattern ^[a-z0-9-]{1,60}$

db_namestringqueryrequired

Name of the database for which the schema is retrieved

lsnstringquery

The Log Sequence Number (LSN) for which the schema is retrieved

timestampstring · date-timequery

The point in time for which the schema is retrieved

formatstringquery

The format of the schema to retrieve. Possible values: - `sql` (default) - `json`

Responses

200Schema definitionapplication/json
objectBranchSchemaResponse
jsonobject
Show child attributes
tablesarray of objectrequired

Tables present in the branch schema.

Show child attributes
Show array items
columnsarray of objectrequired

Columns belonging to this table, each describing a column's name and attributes.

Show child attributes
Show array items
generatedboolean

Whether the column is a generated (computed) column

namestringrequired

Name of the column.

typestringrequired

Postgres data type of the column, for example "integer" or "text".

constraintsarray of object

Table constraints defined in the branch schema, such as primary key, foreign key, unique, and check constraints.

Show child attributes
Show array items
columnsarray of stringrequired

Column names participating in this constraint

minItems 1

Show child attributes

minItems 1

namestring

Optional name of the constraint

referenced_tableobject

For foreign keys - the referenced table information

Show child attributes
columnsarray of stringrequired

Names of the referenced columns

Show child attributes
schemastringrequired

Schema of the referenced table

tablestringrequired

Name of the referenced table

typestringrequired

Type of constraint. Possible values: `primary_key`, `unique`, `foreign_key`

namestringrequired

Name of the table within the schema.

schemastringrequired

Postgres schema (namespace) that contains the table, for example `public`.

sqlstring

Branch schema expressed as SQL DDL statements.

Example response
{
  "json": {
    "tables": [
      {
        "columns": [
          {
            "generated": true,
            "name": "string",
            "type": "string"
          }
        ],
        "constraints": [
          {
            "columns": [
              "string"
            ],
            "name": "string",
            "referenced_table": {
              "columns": [
                "string"
              ],
              "schema": "string",
              "table": "string"
            },
            "type": "string"
          }
        ],
        "name": "string",
        "schema": "string"
      }
    ]
  },
  "sql": "string"
}
defaultGeneral Error. The request may or may not be safe to retry, depending on the HTTP method, response status code, and whether a response was received. - If no response is returned from the API, a network error or timeout likely occurred. - In some cases, the request may have reached the server and been successfully processed, but the response failed to reach the client. As a result, retrying non-idempotent requests can lead to unintended results. The following HTTP methods are considered non-idempotent: `POST`, `PATCH`, `DELETE`, and `PUT`. Retrying these methods is generally **not safe**. The following methods are considered idempotent: `GET`, `HEAD`, and `OPTIONS`. Retrying these methods is **safe** in the event of a network error or timeout. Any request that returns a `503 Service Unavailable` response is always safe to retry. Any request that returns a `423 Locked` response is safe to retry. `423 Locked` indicates that the resource is temporarily locked, for example, due to another operation in progress. application/json
objectGeneralError
codestringrequired

default ""

messagestringrequired

Error message

request_idstring

Unique identifier for the request, useful for debugging. You can set this value manually by including an `X-Request-ID` header in the request. If not provided, the value will be generated automatically.

Example response
{
  "code": "",
  "message": "string",
  "request_id": "string"
}
Documentation menu