> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rwsintegration.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tutorial: PostgreSQL over Live JDBC

> Query RNAcentral, a real public PostgreSQL database, end to end — first unpaged, then cursor-paged

This tutorial runs real queries against **RNAcentral**, the public PostgreSQL database operated by EMBL-EBI. It is officially public: host, user and password are [published by RNAcentral](https://rnacentral.org/help/public-database), so you can reproduce every call here exactly — RWS QA runs these very queries against the deployed service.

| | |
| - | - |
| Engine | PostgreSQL 16 |
| JDBC URL | `jdbc:postgresql://hh-pgsql-public.ebi.ac.uk:5432/pfmegrnargs` |
| User | `reader` |
| Password | `NWDMCE5xdipIjRrp` (published by RNAcentral) — stored with RWS under a name, e.g. `PUBLIC_RNACENTRAL_PASSWORD` |

## Prerequisites

* The `RWS Connect Live JDBC` connection from the [Live JDBC reference](https://docs.rwsintegration.com/en/features/connections/databases.md), with your `x-api-key`
* The password above stored with RWS under a name (email [connect@rwsintegration.com](mailto:connect@rwsintegration.com) once)

## Step 1: A first unpaged query

RNAcentral's `rnacen.rnc_database` table lists the databases it aggregates — a few dozen rows, well under the 5,000-row unpaged cap. In your integration's extract (or straight from `curl`), send:

| Parameter | Value |
| - | - |
| `x_jdbc_url` | `jdbc:postgresql://hh-pgsql-public.ebi.ac.uk:5432/pfmegrnargs` |
| `x_db_user` | `reader` |
| `x_db_password` | `PUBLIC_RNACENTRAL_PASSWORD` |
| `x_sql` | `SELECT id, display_name, example, last_import_date FROM rnacen.rnc_database ORDER BY id` |

```bash theme={null}
curl -G "https://connect.rwsintegration.com/v1/live/jdbc" \
  -H "x-api-key: $RWS_CONNECT_API_KEY" \
  --data-urlencode "x_jdbc_url=jdbc:postgresql://hh-pgsql-public.ebi.ac.uk:5432/pfmegrnargs" \
  --data-urlencode "x_db_user=reader" \
  --data-urlencode "x_db_password=PUBLIC_RNACENTRAL_PASSWORD" \
  --data-urlencode "x_sql=SELECT id, display_name, example, last_import_date FROM rnacen.rnc_database ORDER BY id"
```

The answer comes back in about two seconds:

```json theme={null}
{
  "items": [
    {
      "id": "1",
      "display_name": "ENA",
      "example": null,
      "last_import_date": "2026-05-12T10:31:04"
    },
    {
      "id": "2",
      "display_name": "Rfam",
      "example": null,
      "last_import_date": "2026-05-12T10:31:04"
    }
  ]
}
```

Every value is a string or `null` — numbers, dates and even PostgreSQL `jsonb` columns arrive as text, exactly as the [response contract](https://docs.rwsintegration.com/en/features/connections/databases.md#the-response) promises.

> [!NOTE]
>
> An unpaged `ORDER BY` is fine. Only **paginated** queries must leave ordering to the service.

## Step 2: Paginate with a cursor

`rnacen.rna` holds tens of millions of RNA sequences, so this slice of 12,000 rows needs paging. Add the cursor directives and drop the `ORDER BY` (the service sorts by your unique keys):

| Parameter | Value |
| - | - |
| `x_sql` | `SELECT id, urs, len FROM rnacen.rna WHERE id <= 12000` |
| `x_pagination` | `cursor` |
| `x_unique_keys` | `id` |
| `x_page_size` | `2500` |

The first call carries no `x_cursor`; each response's `next_cursor` feeds the next call's `x_cursor`, until it comes back `null`. In the RWS Application, the cursor pagination config from the [Live JDBC reference](https://docs.rwsintegration.com/en/features/connections/databases.md#pagination) drives this loop for you.

Verified result on the live service: **12,000 rows in 5 pages of 2,500 — 12,000 distinct ids, no duplicates, no gaps** (offset mode returns the identical set).

`id` is the table's primary key, which is exactly what `x_unique_keys` wants: unique over the whole result, never NULL.

## PostgreSQL notes

* The paginated wrapper runs your SQL as a derived table — any valid PostgreSQL `SELECT` works, including CTE-free subqueries and `jsonb` columns.
* A trailing `;` in `x_sql` is stripped automatically.
* `timestamp` columns arrive as `yyyy-MM-ddTHH:mm:ss` strings in the database's wall-clock time; `timestamptz` carries its offset.

## Next steps

> [card] [Live JDBC guide](https://docs.rwsintegration.com/en/features/connections/databases.md)
>
> The full reference: directives, pagination, errors

> [card] [MySQL tutorial](https://docs.rwsintegration.com/en/features/connections/jdbc/mysql.md)
>
> The same flow against Rfam and Ensembl


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.