Skip to main content

The postgres connector supports reading and writing to/from a PostgreSQL server.

Tabset

Read​

Recipe​

read:
- postgres:
host: sql.domain
user: user
password: password
command: |
SELECT *
FROM table

# Optional
port: 5432
database: database
columns:
- column1
- column2

Function​

from wrangles.connectors import postgres
df = postgres.read(
host = 'sql.domain',
user = 'user',
password = 'password',
command = 'SELECT * FROM table'
)

Parameters​

ParameterRequiredData TypeNotes
host✓strHostname or IP address of the server.
user✓strThe user to connect to the database with.
password✓strPassword for the specified user.
command✓strTable name or SQL command to select data.
portintThe Port to connect to. Defaults to 5432.
databasestrThe database to connect to.
columnslistA list with a subset of the columns to import. This is less efficient than specifying in the command.
order_bystrUses SQL syntax to sort the input.
ifstrA condition that will determine whether the action runs or not as a whole.

Write​

Recipe​

write:
- postgres:
host: sql.domain
database: database
table: table
user: user
password: password

# Optional
port: 5432
columns:
- column1
- column2

Function​

from wrangles.connectors import postgres
postgres.write(
df,
host = 'sql.domain',
database = 'database',
table = 'table',
user = 'user',
password = 'password'
)

Parameters​

ParameterRequiredData TypeNotes
df✓DataFrameFunction only. DataFrame of contents to write to the database. Columns must match the target schema.
host✓strHostname or IP address of the server.
database✓strDatabase to be exported to.
table✓strTable to be exported to.
user✓strUser with access to the database.
password✓strPassword for the specified user.
portintThe Port to connect to. Defaults to 5432.
columnslistSubset of the columns to be written. If not provided, all columns will be output.
order_bystrUses SQL syntax to sort the output.
ifstrA condition that will determine whether the action runs or not as a whole.