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

rownum() (and its alias) not recognised in current scope #3366

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Closed

rownum() (and its alias) not recognised in current scope #3366

monetdb-team opened this issue Nov 30, 2020 · 0 comments
Labels
bug Something isn't working invalid This doesn't seem right normal SQL

Comments

@monetdb-team
Copy link

Date: 2013-09-24 10:17:07 +0200
From: @swingbit
To: SQL devs <>
Version: 11.15.3 (Feb2013-SP1)
CC: @njnes

Last updated: 2013-09-27 10:27:13 +0200

Comment 19168

Date: 2013-09-24 10:17:07 +0200
From: @swingbit

User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36
Build Identifier:

If this works (it does):

create table x as select name, 1 as a from sys.tables with data;
SELECT name, a, row_number() OVER(ORDER BY a DESC) from x;

then I would expect this to work as well (it doesn't):

create table x as select name, 1 as a from sys.tables with data;
SELECT name, a, row_number() OVER(ORDER BY a DESC) as r from x where r < 5;

That gives however:
SELECT: identifier 'r' unknown

Using the fully qualified name (where x.r < 5) doesn't help either.

The only solution is to use a subquery:

create table x as select name, 1 as a from sys.tables with data;
WITH y AS (
SELECT name, a, row_number() OVER(ORDER BY x.a DESC) as r FROM x
)
SELECT name, a FROM y WHERE r <= 20;

I think the row_number() function and its alias should be in the scope of the original query.

Reproducible: Always

Comment 19185

Date: 2013-09-27 09:17:44 +0200
From: @njnes

thats not how sql is defined. Only the from part is known in the where block.

Comment 19193

Date: 2013-09-27 10:27:13 +0200
From: @swingbit

You are completely right, my bad.
It was not about the row_number() OVER(), at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right normal SQL
Projects
None yet
Development

No branches or pull requests

1 participant