PostgreSQL

https://www.postgresql.org

Install

Install Ibis and dependencies for the Postgres backend:

Install with the postgres extra:

pip install 'ibis-framework[postgres]'

And connect:

import ibis

con = ibis.postgres.connect()
1
Adjust connection parameters as needed.

Install for Postgres:

conda install -c conda-forge ibis-postgres

And connect:

import ibis

con = ibis.postgres.connect()
1
Adjust connection parameters as needed.

Install for Postgres:

mamba install -c conda-forge ibis-postgres

And connect:

import ibis

con = ibis.postgres.connect()
1
Adjust connection parameters as needed.

Connect

ibis.postgres.connect

con = ibis.postgres.connect(
    user="username",
    password="password",
    host="hostname",
    port=5432,
    database="database",
)
Note

ibis.postgres.connect is a thin wrapper around ibis.backends.postgres.Backend.do_connect.

Connection Parameters

do_connect

do_connect(self, host=None, user=None, password=None, port=5432, database=None, schema=None, url=None, driver='psycopg2')

Create an Ibis client connected to PostgreSQL database.

Parameters
Name Type Description Default
host str | None Hostname None
user str | None Username None
password str | None Password None
port int Port number 5432
database str | None Database to connect to None
schema str | None PostgreSQL schema to use. If None, use the default search_path. None
url str | None SQLAlchemy connection string. If passed, the other connection arguments are ignored. None
driver Literal[‘psycopg2’] Database driver 'psycopg2'
Examples
>>> import os
>>> import getpass
>>> import ibis
>>> host = os.environ.get("IBIS_TEST_POSTGRES_HOST", "localhost")
>>> user = os.environ.get("IBIS_TEST_POSTGRES_USER", getpass.getuser())
>>> password = os.environ.get("IBIS_TEST_POSTGRES_PASSWORD")
>>> database = os.environ.get("IBIS_TEST_POSTGRES_DATABASE", "ibis_testing")
>>> con = connect(database=database, host=host, user=user, password=password)
>>> con.list_tables()
[...]
>>> t = con.table("functional_alltypes")
>>> t
PostgreSQLTable[table]
  name: functional_alltypes
  schema:
    id : int32
    bool_col : boolean
    tinyint_col : int16
    smallint_col : int16
    int_col : int32
    bigint_col : int64
    float_col : float32
    double_col : float64
    date_string_col : string
    string_col : string
    timestamp_col : timestamp
    year : int32
    month : int32

ibis.connect URL format

In addition to ibis.postgres.connect, you can also connect to Postgres by passing a properly formatted Postgres connection URL to ibis.connect

con = ibis.connect(f"postgres://{user}:{password}@{host}:{port}/{database}")

postgres.Backend

create_schema

create_schema(self, name, database=None, force=False)

Create a schema named name in database.

Parameters

Name Type Description Default
name str Name of the schema to create. required
database str | None Name of the database in which to create the schema. If None, the current database is used. None
force bool If False, an exception is raised if the schema exists. False

drop_schema

drop_schema(self, name, database=None, force=False)

Drop the schema with name in database.

Parameters

Name Type Description Default
name str Name of the schema to drop. required
database str | None Name of the database to drop the schema from. If None, the current database is used. None
force bool If False, an exception is raised if the schema does not exist. False

function

function(self, name, *, schema=None)

list_databases

list_databases(self, like=None)

Back to top