# SQL parser detect alias as table column

**URL:** <https://community.cratedb.com/t/sql-parser-detect-alias-as-table-column/259>\
**Category:** SQL\
**Created:** [July 30, 2019, 11:12am UTC](https://community.cratedb.com/t/sql-parser-detect-alias-as-table-column/259 "2019-07-30T11:12:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gorhome](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/gorhome/32/118_2.png) [@gorhome](https://community.cratedb.com/u/gorhome)\
**Post date:** [July 30, 2019, 11:12am UTC](https://community.cratedb.com/t/sql-parser-detect-alias-as-table-column/259/1 "2019-07-30T11:12:15Z")

</div>

Hi guys,  
Have some strange error when I tried to execute the next SELECT query:

```auto
SELECT count(a.id) count_yes, a.stepid stepid_yes, a.stepid
                  FROM activity a
                  WHERE
                    a.type = 4
                    AND
                    a.stepid IN ('1bb64fbb-8d46-4eb5-ab6e-7c0aab679ea7')
                  GROUP BY a.stepid

```

Error:

```auto
SQLActionException[SQLParseException: Couldn't find Field{QueriedTable{DocTableRelation{doc.activity}}.stepid_yes, pointer=Reference{ident=<RefIdent: doc.activity->stepid>, granularity=DOC, position=6, default expression=null, type=text, index type=NOT_ANALYZED, nullable=true, columnstore enabled=false}} in SourceSymbols{inputs={Field{QueriedTable{DocTableRelation{doc.activity}}.count_yes, pointer=count(Ref{doc.activity.id, text})}=IC{0, bigint}, Field{QueriedTable{DocTableRelation{doc.activity}}.stepid, pointer=Reference{ident=<RefIdent: doc.activity->stepid>, granularity=DOC, position=6, default expression=null, type=text, index type=NOT_ANALYZED, nullable=true, columnstore enabled=false}}=IC{2, text}}, nonDeterministicFunctions={}}]

```

Looks like parser detects alias as some table column.

Please note that this works differently on different machines. This query is executed well on the server with Linux but on my local computer with Windows I get this error.

CrateDB version: `4.0.2 -SNAPSHOT-27add9a`

My docker-compose config:

```auto
    crate:
        image: crate
        container_name: ezf_crate
        ports:
          - "4200:4200"
          - "5432:5432"
        expose:
          - 5432
        volumes:
          - ./cratedb/runtime/data:/data    
        environment:
          CRATE_HEAP_SIZE: 1g
        command: crate -Cnode.name=crate-1 -Cnode.store.allow_mmapfs=false

```

---

<div class="post-metadata">

**Author:** ![smu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/smu/32/60_2.png) [@smu](https://community.cratedb.com/u/smu)\
**Post date:** [July 30, 2019, 3:49pm UTC](https://community.cratedb.com/t/sql-parser-detect-alias-as-table-column/259/2 "2019-07-30T15:49:13Z")

</div>

This is indeed a bug, could you create a Github issue please?  
Thanks for reporting already.

---

<div class="post-metadata">

**Author:** ![smu](https://sea2.discourse-cdn.com/flex020/user_avatar/community.cratedb.com/smu/32/60_2.png) [@smu](https://community.cratedb.com/u/smu)\
**Post date:** [August 6, 2019, 9:55am UTC](https://community.cratedb.com/t/sql-parser-detect-alias-as-table-column/259/3 "2019-08-06T09:55:35Z")

</div>

@gorhome  
We’ve fixed this issue by [https://github.com/crate/crate/pull/8985](https://github.com/crate/crate/pull/8985). It will be part of the next 4.0 hotfix release, also the next nightly build will contain it.  
Btw. this bug is not existent at the 3.3 releases and inside 4.x will not happen inside simple queries (no grouping, joins, subselects, etc.)  
Thanks again for reporting! feel free to directly create a github issue next time you’ll encounter a possible bug 🙂
