[Python-ideas] SQL-like way to manipulate Python data structures
Steve Howell
showell30 at yahoo.com
Tue May 29 13:06:24 CEST 2007
--- Aahz <aahz at pythoncraft.com> wrote:
> Think of it this way: if Python requires you to use
> a library for regex
> manipulation, what makes SQL-like data processing
> sufficiently special
> that it belongs in the language itself?
There is a difference.
Regexes would never leverage python expressions
*inside* the regex, even if they were more directly
integrated into the language like Perl. (And, for the
record, I prefer Python's philosophy to make regexes a
module, but I do appreciate the short name, re, and
the fact that it's battery included).
In the case of SQL, I can imagine something like this:
def convert_to_euros(salary): ...
result_set = [[[
select deptno, total(convert_to_euros(salary))
from emp
where country = 'France'
group by deptno
]]] # where emp is a list of dictionaries
Obviously, I understand that you can solve this
problem in Python now, but you either have to do this:
1) Use more bulky way to describe the expression:
sql(..., criteria=lambda row: row['country'] ==
'France')
2) Rely on some library to parse the SQL for you,
which is good enough for the year 2007, but I wonder
why the Python interpreter itself couldn't interpret
the SQL to bytecode (at startup time) just as easily
as, say, SQLAlchemy or sqlite, does at runtime.
____________________________________________________________________________________Pinpoint customers who are looking for what you sell.
http://searchmarketing.yahoo.com/
More information about the Python-ideas
mailing list