# PostgreSQL Destination Reference

An open-source relational database, PostgreSQL is a powerful and well-known system that has received recognition from both its users and the industry at large. Unlike some other database systems, PostgreSQL is completely customizable and yours to do with as you please (assuming, of course, that your instance is self-hosted).

For a more in-depth look at PostgreSQL, [click here](https://www.postgresql.org/about/).

This guide serves as a reference for version 1 of Stitch’s PostgreSQL destination.

## Details and features

* [Stitch features](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#stitch-features)

* [Destination details](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#destination-details)

* [PostgreSQL pricing](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#pricing)

### Stitch features

High-level details about Stitch’s implementation of PostgreSQL, such as supported connection methods, availability on Stitch plans, etc.

| **Release status<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | Released |
| --- | --- |
| **Stitch plan availability<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | All Stitch plans |
| **Stitch supported regions<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | <ul><li>North America (AWS us-east-1)</li><li>Europe (AWS eu-central-1)</li></ul><br><br>Operating regions determine the location of the resources Stitch uses to process your data. [Learn more](https://help.qlik.com/en-US/stitch/security/supported-data-pipeline-regions). |
| **Supported versions<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | 9.3 or higher |
| **Connect API availability<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | **Supported<br>the Success iconSupported**<br><br>This version of the PostgreSQL destination can be created and managed using Stitch’s Connect API. [Learn more](https://help.qlik.com/en-US/stitch/developers/stitch-connect/api#destination-form-properties). |
| **SSH connections<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | **Supported<br>the Success iconSupported**<br><br>Stitch supports using SSH tunnels to connect to PostgreSQL destinations. |
| **SSL connections<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | **Supported<br>the Success iconSupported**<br><br>Stitch will attempt to use SSL to connect by default. No additional configuration is needed. |
| **VPN connections<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | **Unsupported<br>the Remove iconNot supported**<br><br>Virtual Private Network (VPN) connections may be implemented as part of a Premium plan. Contact [Stitch Sales](https://www.stitchdata.com/contact/) for more info. |
| **Static IP addresses<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | **Supported<br>the Success iconSupported**<br><br>This version of the PostgreSQL destination has static IP addresses that can be whitelisted. |
| **Default loading behavior<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | **Upsert**<br><br>**Note**: Append-Only loading will be used if all conditions for Upsert are not met. [Learn more](https://help.qlik.com/en-US/stitch/replication/loading/understanding-loading-behavior). |
| **Nested structure support<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | **Unsupported**<br><br>the Remove icon<br><br>Unupported<br><br><br>Nested data structures will be flattened into relational objects. [Learn more](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#transformations--json-structures). |

### Destination details

Details about the destination, including object names, table and column limits, reserved keywords, etc.

**Note**: Exceeding the limits noted below will result in loading errors or rejected data.

| **Maximum record size<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | 20MB |
| --- | --- |
| **Table name length<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | 63 characters |
| **Column name length<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | 59 characters |
| **Maximum columns per table<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | 250-1,600 |
| **Maximum table size<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | None |
| **Maximum tables per database<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | 100,000 |
| **Case sensitivity<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | Sensitive |
| **Reserved keywords<br><br><br>[the Help icon](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference)** | Refer to the [Reserved keywords documentation](https://help.qlik.com/en-US/stitch/replication/loading/reserved-keywords#postgres-v1-reserved-keywords). |

### PostgreSQL pricing

Pricing for PostgreSQL depends on where your instance is hosted.

* **Self-hosted:** PostgreSQL is open-source, meaning you don’t need to pay an upfront cost to obtain the necessary software. You may, however, have hosting and maintenance costs associated with the server housing the instance. You may have to do a little bit of internal number crunching to figure out these potential costs.

* **Heroku:** Heroku has a [variety of plans to choose from](https://www.heroku.com/pricing), and [a guide to help you select the right plan](https://devcenter.heroku.com/articles/heroku-postgres-plans) for you or your company.

* **Amazon Aurora and RDS:** Amazon offers [a variety of plans](https://aws.amazon.com/rds/postgresql/pricing/) for both on-demand instances and Multi-AZ Deployment. To get an estimate of what your monthly bill might look like, check out their [monthly calculator](http://calculator.s3.amazonaws.com/calc5.html).

* **Google CloudSQL PostgreSQL:** Unlike many other cloud-based data warehouse solutions, [Google’s pricing model](https://cloud.google.com/bigquery/pricing) is based on **usage** and not a fixed-rate. This means that your bill can vary over time.

  Before fully committing yourself to using Google CloudSQL PostgreSQL as your data warehouse, we recommend familiarizing yourself with Google’s pricing model and [using their pricing calculator to estimate your potential costs](https://cloud.google.com/products/calculator/).

## Replication

* [Replication process overview](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#replication-process-overview)

* [Loading behavior](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#loading-behavior)

* [Primary Keys](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#replication--primary-keys)

* [Incompatible sources](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#replication--incompatible-sources)

### Replication process overview

A Stitch replication job consists of three stages:

* [Step 1: Data extraction](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#replication--data-extraction)

* [Step 2: Preparation](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#replication--stitch-internal-pipeline)

* [Step 3: Loading](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#replication--loading)

#### Step 1: Data extraction

Stitch requests and extracts data from a data source. Refer to the [System overview guide](https://help.qlik.com/en-US/stitch/getting-started/basic-concepts-system-overview#system-architecture--extraction) for a more detailed explanation of the Extraction phase.

#### Step 2: Preparation

During this phase, the extracted data is buffered in Stitch’s durable, highly available internal data pipeline and readied for loading. Refer to the [System overview guide](https://help.qlik.com/en-US/stitch/getting-started/basic-concepts-system-overview#system-architecture--preparing) for a more detailed explanation of the Preparation phase.

#### Step 3: Loading

Stitch loads the data into PostgreSQL.

### Loading behavior

By default, Stitch will use **Upsert loading** when loading data into PostgreSQL.

If the conditions for Upsert loading aren’t met, data will be loaded using Append-Only loading.

Refer to the [Understanding loading behavior guide](https://help.qlik.com/en-US/stitch/replication/loading/understanding-loading-behavior) for more info and examples.

### Primary Keys

Stitch requires Primary Keys to de-dupe incrementally replicated data. When tables are created in the destination, Stitch will apply [Primary Key constraints](https://www.postgresql.org/docs/10/static/ddl-constraints.html#DDL-CONSTRAINTS-PRIMARY-KEYS) to columns used as Primary Keys. Primary Key constraints require that column values be unique and not null.

### Incompatible sources

The PostgreSQL destination has reported incompatibilities with some of Stitch's integrations. Refer to the table below for more info.

| **Integration** | **Version** | **Level** | **Reason** |
| --- | --- | --- | --- |
| HubSpot | ANY | the Warning 2 icon<br><br>This destination/integration combination is sometimes incompatible. | [Flattening nested JSON structures](https://help.qlik.com/en-US/stitch/replication/loading/understanding-loading-row-usage-for-nested-data-structures) may result in tables and columns with names that exceed PostgreSQL’s character limit for object names:<br><br><ul> <li>63 characters characters for tables</li> <li>59 characters characters for columns</li></ul> |
| Stripe | ANY | the Warning 2 icon<br><br>This destination/integration combination is sometimes incompatible. | [Flattening nested JSON structures](https://help.qlik.com/en-US/stitch/replication/loading/understanding-loading-row-usage-for-nested-data-structures) may result in tables and columns with names that exceed PostgreSQL’s character limit for object names:<br><br><ul> <li>63 characters characters for tables</li> <li>59 characters characters for columns</li></ul> |

See all [destination and integration incompatibilities.](https://help.qlik.com/en-US/stitch/destinations/destination-integration-compatibility)

## Transformations

* [System tables and columns](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#transformations--system-tables-columns)

* [Data typing](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#transformations--data-typing)

* [JSON structures](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#transformations--json-structures)

* [Column names](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#transformations--column-naming)

* [Timezones](https://help.qlik.com/en-US/stitch/destinations/postgresql/reference#transformations--timezones)

### System tables and columns

Stitch will create the following tables in each integration’s dataset:

* [_sdc_rejected](https://help.qlik.com/en-US/stitch/replication/loading/system-tables-columns/rejected-records-system-table)

Additionally, Stitch will insert [system columns](https://help.qlik.com/en-US/stitch/replication/loading/system-tables-columns) (prepended with `_sdc`) into each table.

### Data typing

Stitch converts data types only where needed to ensure the data is accepted by PostgreSQL. In the table below are the data types Stitch supports for PostgreSQL destinations, and the Stitch types they map to.

* **Stitch type:** The Stitch data type the source type was mapped to. During the Extraction and Preparing phases, Stitch identifies the data type in the source and then maps it to a common Stitch data type.
* **Destination type:** The destination-compatible data type the Stitch type maps to. This is the data type Stitch will use to store data in PostgreSQL.
* **Notes:** Details about the data type and/or its allowed values in the destination, if available. If a range is available, values that exceed the noted range will be [rejected by PostgreSQL](https://help.qlik.com/en-US/stitch/replication/loading/system-tables-columns/rejected-records-system-table).

| **Stitch type** | **Destination type** | **Notes** |
| --- | --- | --- |
| BIGINT | [BIGINT](https://www.postgresql.org/docs/9.4/datatype-numeric.html#DATATYPE-INT) | <ul> <li> <p><strong>Range </strong></p><div><strong><button>the Warning 2 icon</button><div>Values that exceed this range will be rejected by the destination and logged in the &lt;strong&gt;_sdc_rejected&lt;/strong&gt; table. &lt;a href='/en-US/stitch/replication/loading/system-tables-columns/rejected-records-system-table'&gt;Learn more&lt;/a&gt;.</div></strong></div><strong>:</strong>-9223372036854775808 to 9223372036854775807<p></p> </li> </ul> |
| BOOLEAN | [BOOLEAN](https://www.postgresql.org/docs/9.4/datatype-boolean.html) |  |
| DATE | [TIMESTAMP](https://www.postgresql.org/docs/9.4/datatype-datetime.html) | <ul> <li> <p><strong>Description</strong>: Stored in UTC</p> </li> <li> <p><strong>Range </strong></p><div><strong><button>the Warning 2 icon</button><div>Values that exceed this range will be rejected by the destination and logged in the &lt;strong&gt;_sdc_rejected&lt;/strong&gt; table. &lt;a href='/en-US/stitch/replication/loading/system-tables-columns/rejected-records-system-table'&gt;Learn more&lt;/a&gt;.</div></strong></div><strong>:</strong>4713 BC to 294276 AD<p></p> </li> </ul> |
| DOUBLE | [DOUBLE PRECISION](https://www.postgresql.org/docs/9.4/datatype-numeric.html#DATATYPE-FLOAT) |  |
| FLOAT | [DOUBLE PRECISION](https://www.postgresql.org/docs/9.4/datatype-numeric.html#DATATYPE-FLOAT) |  |
| INTEGER | [INTEGER](https://www.postgresql.org/docs/9.4/datatype-numeric.html#DATATYPE-INT) | <ul> <li> <p><strong>Range </strong></p><div><strong><button>the Warning 2 icon</button><div>Values that exceed this range will be rejected by the destination and logged in the &lt;strong&gt;_sdc_rejected&lt;/strong&gt; table. &lt;a href='/en-US/stitch/replication/loading/system-tables-columns/rejected-records-system-table'&gt;Learn more&lt;/a&gt;.</div></strong></div><strong>:</strong>-2147483648 to +2147483647<p></p> </li> </ul> |
| NUMBER | [DECIMAL](https://www.postgresql.org/docs/9.4/datatype-numeric.html#DATATYPE-NUMERIC-DECIMAL) | <ul> <li> <p><strong>Range </strong></p><div><strong><button>the Warning 2 icon</button><div>Values that exceed this range will be rejected by the destination and logged in the &lt;strong&gt;_sdc_rejected&lt;/strong&gt; table. &lt;a href='/en-US/stitch/replication/loading/system-tables-columns/rejected-records-system-table'&gt;Learn more&lt;/a&gt;.</div></strong></div><strong>:</strong>Up to 131,072 digits before the decimal; up to 16,383 digits after<p></p> </li> </ul> |
| STRING | [TEXT](https://www.postgresql.org/docs/9.4/datatype-character.html) | <ul> <li> <p><strong>Description</strong>: No maximum length. No widening will occur if the string length changes.</p> </li> </ul> |

### JSON structures

PostgreSQL destinations don’t have native support for nested data structures. To ensure nested data can be loaded, Stitch will flatten objects and arrays into columns and subtables, respectively. For more info and examples, refer to the [Handling nested data structures guide](https://help.qlik.com/en-US/stitch/replication/loading/understanding-loading-row-usage-for-nested-data-structures).

### Column names

Column names in PostgreSQL:

* Must contain only letters (a-z, A-Z), numbers (0-9), or underscores (`_`)

* Must begin with a letter or underscore

* Must be less than the maximum length of 59 characters. Columns that exceed this limit will be [rejected by PostgreSQL](https://help.qlik.com/en-US/stitch/replication/loading/system-tables-columns/rejected-records-system-table).

* Must not be prefixed or suffixed with any of [PostgreSQL’s or Stitch’s reserved keyword prefixes or suffixes](https://help.qlik.com/en-US/stitch/replication/loading/reserved-keywords#postgres-v1-reserved-keywords)

Stitch will perform the following transformations to ensure column names adhere to the rules imposed by PostgreSQL:

| **Transformation** | **Source column** | **Destination column** |
| --- | --- | --- |
| Remove special characters | `customer#id` or `!CuStoMeRId` | `customerid` and `CuStoMeRId` |
| Remove non-letter leading characters | `4customerid` or `_customerid` | `customerid` |

### Timezones

PostgreSQL will store the value as `TIMESTAMP WITH TIMEZONE`. In PostgreSQL, this data is stored with timezone information and expressed as UTC.

## Compare destinations

**Not sure if PostgreSQL is the data warehouse for you?** Check out the [Choosing a Stitch Destination](https://help.qlik.com/en-US/stitch/destinations/choosing-a-stitch-destination) guide to compare each of Stitch’s destination offerings.