Complex Query Types #416
theelderbeever
started this conversation in
Ideas
Replies: 1 comment
-
@theelderbeever There are lots of interesting ideas here. I think a precursor to this is exposing the internal That will help with composing complex queries. inner_select = QueryString(
"""
SELECT name::text, salary::INTEGER FROM (
VALUES ({}, {})
) t (name, salary)
""",
'Bob',
10000
)
query = QueryString(
"""
UPDATE employees e
SET
salary = t.salary
FROM ({}) WHERE e.name = t.name
""",
inner_select
) As you say, we can create some custom helper classes which generate With the type casting, we could even add something like a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I don't have all of these fully fleshed out in terms of implementation and whether they are really possible but, it would be really cool to seem some of the following for constructing complex queries down the road. Some of the examples are pretty simplistic so I can come up with more relevant uses cases if need be.
So this is all just a food for thought post...
Common Table Expression (CTE)
The Common Table Expression (CTE). Returns a querystring with internals wrapped in a
WITH
clause. The ability to define columns and their types would be useful as well so the selected values could be type castQuery would look like
VALUES
A
VALUES
list. These can be useful when crafting bulkUPDATE
clauses, passing values toCTE
's, or doing some really wild stuff like a Cartesian Product (pretty slow in SQL fyi). Its important to note though that everything gets cast directly to text when coming from aVALUES
list so whatever wraps it would likely need to implement typecastingStandard selection with
VALUES
. Being able to define typecasting the the python select delegate would be super valuable.Cartesian Product just for fun
Subquery
Basically just a query wrapped in parentheses to be shoved after a
FROM
Bulk Update
This can be done in Postgres and SQLite but they are pretty different. This can make a lot of use out of the preceding classes (CTE, SUBQUERY, and VALUES)
A final SQL statement might look something like this in Postgres
This could also be rewritten as a subquery.
Both example would make use of the
VALUES
class though.Beta Was this translation helpful? Give feedback.
All reactions