How to get output from PostgreSQL's VERBOSE functions

11 views
Skip to first unread message

Zsolt Ero

unread,
Jun 9, 2019, 1:15:33 AM6/9/19
to sqlalchemy
Hi, 

I'd like to run a CLUSTER VERBOSE command and save the lines which would normally be displayed in psql's command line. 

How can I do so with SQLAlchemy + psychopg2? 

Zsolt Ero

unread,
Jun 9, 2019, 1:33:28 AM6/9/19
to sqlalchemy
I figured out the keyword is NOTICES.

However this section of the docs doesn't work / didn't had any effect:
https://docs.sqlalchemy.org/en/13/dialects/postgresql.html#notice-logging

What worked was to manually clear and print conn.connection.connection.notices like this:

if notices:
    conn.connection.connection.notices = list()

conn.execute(stmt)

if notices:
    print('----------')
    print('\n'.join(conn.connection.connection.notices))
    print('----------')

Mike Bayer

unread,
Jun 9, 2019, 10:19:39 AM6/9/19
to sqlal...@googlegroups.com


On Sun, Jun 9, 2019, at 1:33 AM, Zsolt Ero wrote:
I figured out the keyword is NOTICES.

However this section of the docs doesn't work / didn't had any effect:

that document assumes one is familiar with logging in general which it probably should not, so did you also set up logging config?   If you call this ahead of time:

logging.basicConfig()

otherwise the feature is broken






What worked was to manually clear and print conn.connection.connection.notices like this:

if notices:
    conn.connection.connection.notices = list()

conn.execute(stmt)

if notices:
    print('----------')
    print('\n'.join(conn.connection.connection.notices))
    print('----------')


--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zsolt Ero

unread,
Jun 9, 2019, 4:16:22 PM6/9/19
to sqlalchemy
Thanks with logging.basicConfig() it indeed works.

You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/89NEx4yA1ww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.

To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
Reply all
Reply to author
Forward
0 new messages