Skip to content

support Cursor attribute to provide ANSI SQL State Code #220

Description

@dataders

While a Cursor attribute providing SQL State Code is not officially a part of PEP 249: Python DB API 2.0 spec, there is an ANSI-standardized "SQL state code".

Many database drivers provide this as a Cursor attribute, dbt was able to depend on these drivers to provide it for ConnectionManager.get_response() method, which will report to users after successful queries the kind of operation performed (SELECT, INSERT, CREATE) and the numbers of rows affected. Originally the Redshift adapter for dbt, was supported by the psycopg2 driver, which provides this information in statusmessage.

As reported in dbt-labs/dbt-redshift#785, after migrating the driver dependency to redshift-connector, users are in a degraded state and receive less information than previously due to the SQL state not being available.

Support for SQL state amongst popular analytics database drivers

DriverCursor attribute (docs)
psycopg2statusmessage
snowflake-connector-pythonsqlstate

Ideal implementation

Postgres's CommandComplete message

CommandTagrows indicates the number of rows
INSERTINSERT 0 rowsinserted
DELETEDELETE rowsdeleted
UPDATEUPDATE rowsupdated
MERGEMERGE rowsinserted, updated, or deleted
SELECT / CREATE TABLE ASSELECT rowsretrieved
MOVEMOVE rowsursor's position has been changed by
FETCHFETCH rowsthat have been retrieved from the cursor
COPYCOPY rowscopied, only in PostgreSQL 8.2 and later

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions