PostgreSQL
This page gives information to connect Appsmith to a PostgreSQL database and to read and write data in your applications.
Connect PostgreSQL
If you are a cloud user, you must configure the pg_hba.conf
file to whitelist the IP addresses 18.223.74.85
and 3.131.104.27
of the Appsmith deployment on your database instance before connecting to a database. See Client Authentication for more details.
Connection parameters
The following section is a reference guide that provides a complete description of all the parameters to connect to a PostgreSQL database.
Connection Mode
- Read Only: This mode permits read-only transactions by default.
- Read/Write: This mode permits both read-write transactions by default.
Host Address
Port
5432
by default if you do not specify one. Database Name
Username
Password
SSL Mode
- Default: The default SSL Mode is Prefer.
- Allow: First try a non-SSL connection; if that fails, try an SSL connection. The client can connect with or without SSL.
- Prefer: First try an SSL connection; if that fails, try a non-SSL connection. The client tries to connect with SSL but falls back to an unencrypted connection if SSL is unavailable.
- Require: Only try an SSL connection. Rejects the connection if SSL is not available.
- Disable: Only try a non-SSL connection. Disallows all administrative requests over HTTPS. It uses a plain unencrypted connection.
Query PostgreSQL
The following section provides examples of creating basic CRUD queries on PostgreSQL.
For the SQL syntax, see the official PostgreSQL documentation.
Fetch data
SELECT * FROM users LIMIT {{ tableUsers.pageSize }} OFFSET {{ tableUsers.pageOffset }};
In the above example, tableUsers
is the name of the Table widget used to display the data using server-side pagination.
See how to guide on Fetch and Filter data in SQL.
Insert data
INSERT INTO users
(name, gender, email)
VALUES
(
{{ nameInput.text }},
{{ genderDropdown.selectedOptionValue }},
{{ emailInput.text }}
);
In the above example, nameInput
, genderDropdown
, and emailInput
are the names of the widgets used to capture input from the user for name, gender and email fields, respectively.
See how-to guide on Insert and Update data in SQL.