Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "AS" syntax and some standard SQL functions #14

merged 3 commits into from Oct 5, 2013


Copy link

@uranusjr uranusjr commented Oct 5, 2013

See for implemented standard functions.

I'm not sure where the docs should go, so I didn't add any, sorry. :p
Might want to hint the user in the docs that they can import mosql.function as f to use f.sum or similar. Don't from mosql.function import * unless you know want you're doing because it will override the built-in min, max and sum.

uranusjr added 3 commits Oct 5, 2013
I added an extra layer "_query" between str and raw to use internally.
Statement-based callables and "identifier" now both return a _query
instead of str. This difference is used in "identifier" to avoid
unintended processing to _query objects that represent subqueries.

Now you can do this:

>>> subquery = select('person', select=('last_name',))
>>> print select('person', where={'first_name': paren(subquery)})

And get:

SELECT * FROM "person" WHERE "first_name" = (SELECT "last_name" FROM

The above test has been added to
Also added two tests to
moskytw added a commit that referenced this issue Oct 5, 2013
Implement "AS" syntax and some standard SQL functions
@moskytw moskytw merged commit c729d21 into moskytw:dev Oct 5, 2013
This was referenced Oct 5, 2013
Copy link

moskytw commented Oct 13, 2013

I took a deeper look at your code, and I did two changes:

  1. Actually, "a AS x, b AS y, ..." can be treated as a pair list, so I integrated the as_ function into identifier. Now you can use AS feature via putting them in a 2-tuple:

    print select('person', select=(('name', 'n'), ))
    SELECT "name" AS "n" FROM "person"

    See 051e986 for detail.

  2. I use closure to implement the simple functions. See 48898d6 for detail.


Copy link
Contributor Author

uranusjr commented Oct 13, 2013

Love the tuple syntax in select, thx.

What I had in mind behind the class-based implementation was that the end user may wish to add some specific functions. By using a class, users can implement other functions more easily if they want to by subclassing Function. (That's also why Function was in

But this implementation is certainly nicer in the current context. I'm fine with it, too.

Copy link

moskytw commented Oct 13, 2013

Yes, it is enough to use closure to implement at this time. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants