---
layout: integration
title: Query Neon Postgres
description: Store and query rows in a Neon serverless Postgres database from an Appwrite Function
date: 2026-11-06
featured: false
isPartner: true
isNew: true
cover: /images/integrations/query-neon/cover.avif
category: databases
product:
    vendor: Neon
    description: "Neon is a serverless Postgres platform that separates storage and compute, with autoscaling and database branching."
platform:
    - 'Self-hosted'
    - 'Cloud'
---

[Neon](https://neon.com/) is a serverless Postgres platform. It separates storage from compute, so databases scale with traffic, suspend when idle, and can be branched like code for previews and tests.

# How does the integration work?

The **Query Neon Postgres** function template shows how to work with a Neon database from Appwrite Functions using the `postgres` driver over TLS. On its first request, the function creates a `warehouses` table if it doesn't exist. Each `GET` request then inserts a warehouse with a random location and capacity and returns up to 100 rows as JSON.

The function keeps its connection between executions, so warm requests skip the connection setup. Use it as a starting point for your own SQL queries.

# How to implement

To implement the Neon integration, there are several steps you must complete:

## Step 1: Create a Neon project

Sign in to the [Neon console](https://console.neon.tech/) and create a project. Open the project's connection details and save these values:

| Value | Example |
| --- | --- |
| Host | `ep-still-sea-a792sh84.eu-central-1.aws.neon.tech` |
| Database | `neondb` |
| Role | The database user, for example `neondb_owner` |
| Password | The role's password |
| Endpoint ID | The first part of the host, for example `ep-still-sea-a792sh84`. If the host is a pooled one, leave out the `-pooler` suffix. |

## Step 2: Create the Appwrite Function

For this step, you must [create an account on Appwrite Cloud](/sign-up) or [self-host Appwrite](/docs/advanced/self-hosting) if you haven't already. If you self-host Appwrite, enable a Node.js runtime in `_APP_FUNCTIONS_RUNTIMES` and follow the [Functions configuration guide](/docs/advanced/self-hosting/configuration/functions) so function domains work.

In the Appwrite Console, go to **Functions**, open the **Templates** tab, search for **Query Neon Postgres**, and click **Create from template**. Fill in the **Template variables**:

| Variable | Value |
| --- | --- |
| `PGHOST` | The host |
| `PGDATABASE` | The database name |
| `PGUSER` | The role |
| `PGPASSWORD` | The password |
| `ENDPOINT_ID` | The endpoint ID |

Choose **Connect your repository** to clone the template into a Git repository where you can write your own queries, or **Connect later** to deploy it right away. Then click **Create and deploy**.

## Step 3: Test the function

Copy the function's domain from the **Domains** tab and send a request:

```bash
curl https://<FUNCTION_DOMAIN>
```

The response lists the rows in the `warehouses` table:

```json
[
  { "id": 1, "location": "Street 108, Earth", "capacity": 50 },
  { "id": 2, "location": "Street 675, Earth", "capacity": 70 }
]
```

Every request adds another row. Requests with other methods return `404`. You can inspect the table in the Neon console's SQL editor.

The template allows anyone to execute the function, so anyone who finds its domain can add rows to your database. Before you query your own data, replace `Any` in the function's [execute access](/docs/products/functions/functions#execution-access) with narrower [roles](/docs/advanced/security/permissions#permission-roles), such as `Users`, and call the function [with an Appwrite SDK](/docs/products/functions/execute#sdk) instead of its domain.

# Read more about Neon and Appwrite Functions

If you would like to learn more about Neon and Appwrite Functions, we have some resources that you should visit:

- [Connect a Node.js application to Neon](https://neon.com/docs/guides/node)
- [Integrate SQL, NoSQL, vector, graph, or any database into your Appwrite project](/blog/post/integrate-sql-nosql-vector-graph-or-any-database-into-your-appwrite-project)
- [Learn more about Functions templates in Appwrite docs](/docs/products/functions/templates)
- [Query Neon Postgres template source](https://github.com/appwrite/templates/tree/1.2.0/node/query-neon-postgres)
