Article
· Mar 29, 2023 1m read

Named Parameter In SQL with Python

Quick Tips: Total Productive Maintenance

Named parameters can be achieved with SQLAlchemy :
 

from sqlalchemy import create_engine, text,types,engine

_engine = create_engine('iris+emb:///')

with _engine.connect() as conn:
    rs = conn.execute(text("select :some_private_name"), {"some_private_name": 1})
    print(rs.all())

or with native api

from sqlalchemy import create_engine, text,types,engine

# set URL for SQLAlchemy
url = engine.url.URL.create('iris', username='SuperUser', password='SYS', host='localhost', port=33782, database='FHIRSERVER')

_engine = create_engine(url)

with _engine.connect() as conn:
    rs = conn.execute(text("select :some_private_name"), {"some_private_name": 1})
    print(rs.all())

requirements.txt

sqlalchemy==1.4.22
sqlalchemy-iris==0.5.0
irissqlcli

It's working today, on IRIS 2021.2+

Discussion (0)1
Log in or sign up to continue