Skip to main content

Postgres

Overview

This connector provides a connection to a Postgres database. It is a wrapper around the standard Psycopg2 Python library.

Requirements

Before creating the connector, you will need the following information available for the Postgres server you are connecting to.

  • hostname or IP address
  • port
  • username
  • password
  • database name

Creating

To add an instance of the Postgres connector, you can use the Web UI or the CLI.

$ sand connectors create postgres --name myDB --hostname postgres01 \
--password password123 --username user123 --port 5432 \
--database production
✅ Connector created successfully!
Connector ID: mod_01jhnq79hwfppbnkm8pkndkr28

Usage

To use this connector, you first must initialize the connector in a step:

postgres = sandgarden.connectors['myDB']

Then call the API just as you would the Psycopg2 library:

with postgres.cursor(cursor_factory=RealDictCursor) as cur:
cur.execute("SELECT * FROM messages WHERE ticket_id = %s ORDER BY id ASC", (ticket_id,))
messages = cur.fetchall()