Generating SQL queries in Python

Boudewijn Rempt boudewijn at tryllian.com
Wed May 23 04:59:07 EDT 2001


Karl Schmid wrote:

> Hi,
> 
> I am currently writing a python program that heavily interacts with SQL
> databases (PostgreSQL). The SQL queries are kind of hard-coded at many
> places in the program and need to be changed when the database structure
> changes (or when a different database system is used, e.g. MySQL).
> 
> I was wondering whether there is a solution available in python that
> allows to introduce an additional layer of functions for generating SQL
> queries so that the code can be more easily adapted to changes in the
> database structure or system.
> 
> Any information on modules or documentation dealing with this problem is
> welcome.
> 

I've written something like that for MySQL - but it should be readily 
portable to PostgreSQL. You define a kind of repository with a description 
of your tables and relations, and the module automatically generates 
queries and joins.

http://www.valdyas.org/python/dbobj.html

The version I use in Kura is a bit more current:

http://www.valdyas.org/linguistics/index.html

-- 
Boudewijn | http://www.valdyas.org



More information about the Python-list mailing list