Comments (4)
It indeed is a problem. I will try to fix it. Thanks for reporting it. :)
from mosql.
It is super crazy if you build subquery with the current stuff:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from mosql.util import raw, paren, identifier
from mosql.query import select
def as_(a, b):
return '%s AS %s' % (identifier(a), identifier(b))
print select(
select = 'name',
table = raw(as_(
raw(paren(
select('person', select='name')
)),
'name'
))
)
# -> SELECT "name" FROM (SELECT "name" FROM "person") AS "name"
I will find the best way to integrate this feature into MoSQL.
from mosql.
With #12 and #14, the "person" example can now be written with a slightly different (simpler) syntax:
print select(select='name', table=as_(paren(select('person', select='name')), 'name'))
And the funky example I provided becomes
x = select('fruits', select=('type', as_(min('price'), 'minprice')), group_by=('type',))
join_x = join(as_(paren(x), 'x'), {'fruits.type': 'x.type', 'fruits.price': 'x.minprice'})
select('fruits', select=('fruits.type', 'fruits.variety', 'fruits.price'), joins=(join_x,))
resulting
SELECT "fruits"."type", "fruits"."variety", "fruits"."price" FROM "fruits"
INNER JOIN (SELECT "type", MIN("price") AS "minprice" FROM "fruits" GROUP BY "type") AS "x"
ON "fruits"."price" = "x"."minprice" AND "fruits"."type" = "x"."type"
Notice that you'll need to provide the paren
calls for yourself. I'll look into how we can simplify these calls. At least the as_
functions should have the ability to add parentheses automatically.
from mosql.
Thanks @uranusjr. The commits are merged in dev branch now. :D
from mosql.
Related Issues (20)
- Port MoSQL to Python 3 HOT 1
- Fix the wrong doc caused by monkey patch HOT 1
- The print statements cause the fails in doctest in Python 3 HOT 3
- The test of SQLite should be split into doctest and example HOT 1
- 支援一些特殊語法 HOT 4
- help not really help for insert, delete, select ,, etc. HOT 12
- Add doc for subquery and the `AS` feature. HOT 1
- AS does not work in JOIN HOT 1
- "Unloading" MySQL fixes HOT 1
- Multi-row INSERT HOT 6
- mosql.sqlite leaks docs
- mosql.func leaks docs HOT 1
- benchmark script HOT 1
- Coercing values during chaining HOT 1
- BigQuery support HOT 1
- Migrate the Tests to Nose HOT 5
- 0.9.1 does not work on Python 3 HOT 1
- SQLite patch should stringify True and False to 1 and 0
- Expand ConnContext and make it as a new feature HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mosql.