Lijo Jose
Lijo Jose

Reputation: 337

Error while adding application_name as a parameter in dask.read_sql_table

I am trying to create a dask dataframe from a table in postgres. I would like to pass the application_name = 'myapp' as a standard for monitoring and tracking DB activity.

But when am trying to add the parameter, I getting below error.

ddf = dd.read_sql_table('table', 
                        uri, 
                        schema='schema', 
                        index_col='index_col', 
                        engine_kwargs={'application_name':'myapp'})

TypeError: Invalid argument(s) 'application_name' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine. Please check that the keyword arguments are appropriate for this combination of components.

Upvotes: 2

Views: 730

Answers (2)

Amrith Raj Herle
Amrith Raj Herle

Reputation: 875

  • PostgreSQL Database :

The following works in sqlalchemy==1.3.10

    # Establish database connection via sqlalchemy

    sqlalchemy_connection_kwargs = {'connect_args': {'application_name': 'herles_application'}}

    connection = create_engine(sqlalchemy_connection_string, **sqlalchemy_connection_kwargs)

If you are using psycopg2-binary==2.8.4 native connection

native_connection = psycopg2.connect(user=cred['username'],
                                     password=cred['password'],
                                     host=cred['host'],
                                     port=cred['port'],
                                     database=cred['databaseName'],
                                     application_name="herles_application")

Upvotes: 0

mdurant
mdurant

Reputation: 28683

It turns out the correct syntax was

ddf = dd.read_sql_table('table', 
                        uri, 
                        schema='schema', 
                        index_col='index_col', 
                        engine_kwargs={'connect_args': {'application_name': 'myapp'})

since the call to make the sqlalchemy engine looks like

engine = create_engine(uri, connect_kwargs={'application_name':' myapp'})

Upvotes: 3

Related Questions