akarshan2701 / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

CTE: Table name Scope Error? #222

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Before submitting a bug, please check the FAQ:
http://www.h2database.com/html/faq.html

What steps will reproduce the problem?
(simple SQL scripts or simple standalone applications are preferred)
1.create table t (n int)
2.insert into t (n) values(1)
3.with recursive t(n) as (
select 0
union all
select n + 1 from t where n < 9
)
select * from t

===Result===
N
-
1

or

4.with recursive t(x) as (
select 0
union all
select x + 1 from t where x < 9
)
select * from t

===Result===
列 "X" が見つかりません
Column "X" not found; SQL statement:
with recursive t(x) as ( 
select 0 
union all 
select x + 1 from t where x < 9 
) 
select * from t [42122-140] 42S22/42122 (ヘルプ)
org.h2.jdbc.JdbcSQLException: 列 "X" が見つかりません
Column "X" not found; SQL statement:
with recursive t(x) as ( 
select 0 
union all 
select x + 1 from t where x < 9 
) 
select * from t [42122-140] 
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:327) 
    at org.h2.message.DbException.get(DbException.java:167) 
    at org.h2.message.DbException.get(DbException.java:144) 
    at org.h2.expression.ExpressionColumn.optimize(ExpressionColumn.java:127) 
    at org.h2.expression.Operation.optimize(Operation.java:152) 
    at org.h2.command.dml.Select.prepare(Select.java:738) 
    at org.h2.command.dml.SelectUnion.prepare(SelectUnion.java:233) 
    at org.h2.command.Parser.parserWith(Parser.java:4011) 
    at org.h2.command.Parser.parsePrepared(Parser.java:426) 
    at org.h2.command.Parser.parse(Parser.java:275) 
    at org.h2.command.Parser.parse(Parser.java:247) 
    at org.h2.command.Parser.prepare(Parser.java:201) 
    at org.h2.command.Parser.prepareCommand(Parser.java:214) 
    at org.h2.engine.Session.prepareLocal(Session.java:434) 
    at org.h2.engine.Session.prepareCommand(Session.java:384) 
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1071) 
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:163) 
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:151) 
    at org.h2.server.web.WebApp.getResult(WebApp.java:1310) 
    at org.h2.server.web.WebApp.query(WebApp.java:1003) 
    at org.h2.server.web.WebApp$1.next(WebApp.java:966) 
    at org.h2.server.web.WebApp$1.next(WebApp.java:955) 
    at org.h2.server.web.WebThread.process(WebThread.java:161) 
    at org.h2.server.web.WebThread.run(WebThread.java:88) 
    at java.lang.Thread.run(Thread.java:619) 

What is the expected output? What do you see instead?

Output: 3
N
-
0
1
2
3
4
5
6
7
8
9

or Output: 4

X
-
0
1
2
3
4
5
6
7
8
9

What version of the product are you using? On what operating system, file
system, and virtual machine?

H2: Head(r2846)
OS: Windows XP SP3
Java: 1.6.0_20

Do you know a workaround?

No

How important/urgent is the problem for you?

Not so important/urgent

In your view, is this a defect or a feature request?

Defect

Please provide any additional information below.
---h2w.bat---
@start %JAVA_HOME%/bin/javaw.exe -server -Xms512m -Xmx512m 
-Dh2.largeTransactions=true -cp "h2-1.2.140.jar;%H2DRIVERS%;%CLASSPATH%" 
org.h2.tools.Console %*
---JDBC URL---
jdbc:h2:test

Original issue reported on code.google.com by byouinza...@gmail.com on 11 Aug 2010 at 7:07

GoogleCodeExporter commented 8 years ago
5.explain 
with recursive t(n) as ( 
select 0 
union all 
select n + 1 from t where n < 9 
) 
select * from t;

PLAN  
---
SELECT T.N
FROM PUBLIC.T /* PUBLIC.T.tableScan */

6.drop table t;

7.explain 
with recursive t(n) as ( 
select 0 
union all 
select n + 1 from t where n < 9 
) 
select * from t;

PLAN
---
SELECT T.N
FROM ((SELECT 0
FROM SYSTEM_RANGE(1, 1) /* PUBLIC.RANGE_INDEX */) UNION ALL (SELECT (N + 1)
FROM PUBLIC.T /* PUBLIC.T.tableScan */
WHERE N < 9)) /* null */

Original comment by byouinza...@gmail.com on 11 Aug 2010 at 7:46

GoogleCodeExporter commented 8 years ago
Hi,

Thanks for reporting this issue. I have added it to the roadmap. It will be 
implemented eventually, but currently the priority is relatively low.

Original comment by thomas.t...@gmail.com on 15 Aug 2010 at 8:41

GoogleCodeExporter commented 8 years ago
I have added the feature to the roadmap.

Original comment by thomas.t...@gmail.com on 15 Aug 2010 at 8:45

GoogleCodeExporter commented 8 years ago

Original comment by thomas.t...@gmail.com on 15 Aug 2010 at 8:45