-
Notifications
You must be signed in to change notification settings - Fork 145
introduce CTE + RECURSIVE #656
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
Conversation
valq7711
commented
Apr 3, 2021
@mdipierro |
@mdipierro |
I am sorry. Been swamped. Your PR are particularly complex. I will review asap. |
I love this but I have some requests:
|
1, 2 - yes of course, I just needed your approval of the general concept |
3. Not specifically. Just because I am afraid people will not use this
feature if too complex.
…On Sun, Apr 25, 2021, 11:11 valq7711 ***@***.***> wrote:
1, 2 - yes of course, I just needed your approval of the general concept
3 - ? Is it about RestAPI?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#656 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHLZT5YQXADGL2IV3XY3ELTKRLLNANCNFSM42KYKYQA>
.
|
Those people who need recursive select will definitely use it. We have simplest syntax!!!, just compare due to self-reference, single call can be look like this (it is easy to implement) works_for = db(org.name == 'Alice').cte(
'works_for',
org.id,
org.name.with_alias('top_boss'), # i.e. Alice is top_boss
org.name,
Expression(db, '1', type = 'integer').with_alias('xdepth')
).union( lambda works_for: \
db((org.boss == works_for.id) & (org.id != org.boss)).nested_select(
org.id,
works_for.top_boss,
org.name,
(works_for.xdepth + 1).with_alias('xdepth')
)
) |
Also, CTE seems to be better than nested select |
user = db(db.auth_user.id == db.profile.user).cte(
'user',
db.auth_user.ALL,
db.profile.id.with_alias('profile_id'),
db.profile.image
)
>>> db(user.username.startswith('v'))._select(user.ALL))
WITH
user(id, username, email, password, first_name, last_name, sso_id, action_token, last_password_change, profile_id, image)
AS (SELECT
"auth_user"."id",
"auth_user"."username",
"auth_user"."email",
"auth_user"."password",
"auth_user"."first_name",
"auth_user"."last_name",
"auth_user"."sso_id",
"auth_user"."action_token",
"auth_user"."last_password_change",
"profile"."id" AS profile_id,
"profile"."image"
FROM "auth_user", "profile"
WHERE ("auth_user"."id" = "profile"."user")
)
SELECT
"user"."id",
"user"."username",
"user"."email",
"user"."password",
"user"."first_name",
"user"."last_name",
"user"."sso_id",
"user"."action_token",
"user"."last_password_change",
"user"."profile_id"
"user"."image"
FROM "user"
WHERE ("user"."username" LIKE 'v%' ESCAPE '\');" |
Thank you so much for CTE support. That will make a few things way easier and with less database queries. |