[Python] Eliminate spaces in raw SQL in python script

Discussão em 'Python' iniciado por Stack, Maio 7, 2025.

  1. Stack

    Stack Membro Participativo

    I am creating a sql-view with help of sqlalchemy, my code:

    from sqlalchemy.sql import text
    from app.core.config import settings

    # CREATE VIEWS
    all_recent_tasks = text(
    f"CREATE OR REPLACE VIEW all_recent_tasks AS \
    SELECT COUNT(*) FROM tasks WHERE creation_time >= NOW() - INTERVAL '{settings.common.metrics_pause_minutes} minutes';"
    )


    The code prints

    DEBUG__ CREATE OR REPLACE VIEW all_recent_tasks AS SELECT COUNT(*) FROM tasks WHERE creation_time >= NOW() - INTERVAL '25 minutes';


    Is it possible to save current format, but eliminate spaces after 'AS'

    I mean that I don't want ugly format

    all_recent_tasks = text(
    f"CREATE OR REPLACE VIEW all_recent_tasks AS \
    SELECT COUNT(*) FROM tasks WHERE creation_time >= NOW() - INTERVAL '{settings.common.metrics_pause_minutes} minutes';"
    )

    Continue reading...

Compartilhe esta Página