Comments (7)
I'm seeing several possible solutions:
1. Back to square one: do better work at parsing a query, plant the "col1",
"col2" aliases directly inside the query, without adding the wrapping "(select
...) col1".
This means identifying and replacing existing aliases, with or without the "AS"
keyword.
I think this will be very complicated.
2. Back to square zero: create a temporary table into which the results of the
user's query are inserted. We use the _wrap_select_list_columns to identify
the number of columns in the original query.
- We may choose to pad the original query with NULLs so as to reach a
pre-defined number of columns
- Or we may just detect the number of columns, thereby writing the correct
INSERT INTO my_tmp (col1, ..., coln) SELECT...
- Or we may yet modify the original query by wrapping an outer query around it,
making for a temporary table, with our own desired aliases:
SELECT col1, ..., coln FROM (__original_query__) select_original
Thoughts?
Original comment by [email protected]
on 6 Nov 2011 at 6:45
from common-schema.
Last thought, is there a way to somehow fix the incorrectness of the GROUP BY
problem?
Original comment by [email protected]
on 6 Nov 2011 at 6:46
from common-schema.
Shlomi,
I think we should aim for option 1 - parse and insert aliases propery, without
wrapping columns in (...).
I recall there was something complicated about that approach, but it escapes me
what that was exactly.
Alternatively, we could rewrite queries to look like this:
SELECT NULL AS _dummy, @1:=continent, @2:=count(*), ..
where _dummy is a generated column so you have a known column to fetch in the
cursor loop, and @1, @2 etc are variables to capture the actual values.
This should be relatively simple (inject dummy column immediately after the
top-level SELECT, and inject variable after each top-level comma). The bonus to
this approach is that you get unlimited number of column references - simply
replace every variable reference with its corresponding user-defined variable.
The downside of that approach is that it won't work with UNION in the top-level
query - those queries would have to be wrapped in a SELECT of their own.
I'll try and investigate how hard it would be to go for solution 1, ok?
Original comment by roland.bouman
on 6 Nov 2011 at 9:26
from common-schema.
Roland,
To answer your question, the problem was that it was very difficult to analyze
the aliases for some columns; sometimes with AS, sometimes without.
I think the solution with user variables is equally complicated, since you
would have to wrap the exact definition in order to avoid priority issues:
SELECT @col1 := val + bonus AS amount
vs
SELECT (@col1 := (val + bonus)) AS amount
Need to verify with myself that this is actually required.
If it does: if you can do the latter properly, that also solves your first
problem.
Original comment by [email protected]
on 7 Nov 2011 at 10:21
from common-schema.
Shlomi, good point - it looks like whatever solution we take, at the core we
simply need to properly parse column expressions and their aliases.
I think it should be possible to use a rather simple model for this. I will get
back at this later this evening.
Original comment by roland.bouman
on 7 Nov 2011 at 11:09
from common-schema.
Roland,
The solution of using temporary tables can make for an easier workaround, I
think. I'll give it further thought as well.
Original comment by [email protected]
on 7 Nov 2011 at 11:17
from common-schema.
Fixed in revision 149
Solution based on parsing+modifying query statement
Original comment by [email protected]
on 10 Nov 2011 at 11:04
- Changed state: Verified
from common-schema.
Related Issues (20)
- The split query_script statement will not allow the use of PARTITION selection syntax feature of MySQL 5.6 HOT 3
- common_schema.json_to_xml is not parsing valid json array elements. HOT 3
- Documentation issue - Google is blocking access to query script execution page HOT 2
- Looking for innodb_index_stats in the wrong schema in mysql 5.6 HOT 4
- Bug in the _as_datetime() function HOT 4
- SUPER privilege error with Amazon RDS HOT 7
- Documentation issue
- sql_range_partition does not function as expected when the column is a timestamp integer
- split does not work if stop is specified HOT 1
- Routine dependencies fails on replace function
- Routine dependencies confuses default schema HOT 1
- Routine dependencies returns column name from a join <using> clause HOT 1
- Routine dependencies confused by <insert ... on duplicate update> HOT 1
- Routine dependencies misinterpret column when using insert statement schema name HOT 1
- common_schema 2.2 fails on install HOT 1
- Patch for /common_schema/routines/general_internal/_get_json_token.sql
- Minus breaks extract_json_value and anything dependent on json_to_xml HOT 1
- Errors when trying to install script via SQLYog HOT 1
- add next partition not using datetime fail after a value >= 10000 (or thereabouts)
- json_to_xml - malformed charset on output
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 common-schema.