Close
    logoCloudomation Docs

    TaskSQLPG

    class tasks.task_sqlpg.TaskSQLPG

    Interact with a PostgreSQL database. This task supports the execute, fetch, fetchrow, and fetchval commands. Each command expects an SQL query and returns the status, list, record or field value respectively.

    Consult the PostgreSQL SQL language documentation at https://www.postgresql.org/docs/12/tutorial-sql.html for more information.

    Inputs

    NameTypeDefaultDescription
    client_certstrNone
    client_keystrNone
    databasestrpg_catalog
    executestrNone
    executemanylistNone
    fetchstrNone
    fetchrowstrNone
    fetchvalstrNone
    hoststr
    ip_privstrNone
    paramslistNone
    passwordstrNone
    portint5432
    server_castrNone
    temp_pathstr/tmp
    transactionlistNone
    userstrpostgres

    Outputs

    NameTypeDefaultDescription
    resultobject
    execution_idintThe ID of the task execution
    messagestrThe ended message for the task. If the task ended with an error, the message will contain information about what went wrong
    statusstrThe ended status for the task. Either "success" or "error".

    Constants

    input_list = ['client_cert', 'client_key', 'database', 'execute', 'executemany', 'fetch', 'fetchrow', 'fetchval', 'host', 'ip_priv', 'params', 'password', 'port', 'server_ca', 'temp_path', 'transaction', 'user']output_list = ['result']version = 1

    Methods

    log (message)
    run ()

    Example

    import flow_api
    def handler(system: flow_api.System, this: flow_api.Execution):
    postgres_server_version = this.task(
    'SQLPG',
    host='my-postgres-server',
    fetchval='SELECT version()',
    ).get('output_value')['result']
    this.log(postgres_server_version=postgres_server_version)
    postgres_server_events = this.task(
    'SQLPG',
    host='my-postgres-server',
    database='testlocal',
    execute='CREATE TABLE IF NOT EXISTS mytab (a int, b int);',
    ).get('output_value')['result']
    this.log(postgres_server_events=postgres_server_events)
    postgres_server_events = this.task(
    'SQLPG',
    host='my-postgres-server',
    database='testlocal',
    transaction=[['INSERT INTO mytab (a, b) VALUES ($1, $2);', (1,2)],
    ['INSERT INTO mytab (a, b) VALUES ($1, $2);', (3,4)],
    ['INSERT INTO mytab (a, b) VALUES ($1, $2);', (6,7)]
    ],
    ).get('output_value')['result']
    this.log(postgres_server_events=postgres_server_events)
    postgres_server_events = this.task(
    'SQLPG',
    host='my-postgres-server',
    database='testlocal',
    executemany=['INSERT INTO mytab (a, b) VALUES ($1, $2);',
    [(1,2), (3,4), (6,7)]],
    ).get('output_value')['result']
    this.log(postgres_server_events=postgres_server_events)
    return this.success('all done')
    Previous
    TaskSQLORACLE
    Next
    TaskSSH