Bug 87 : Postgres requires "AS" keyword for column alias
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
1.1.0
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
07/03/2009
Updated 
07/03/2009
Type 
Bug
 
Attachments 
No attachments

From Topic 122 ...

I have a very simple object that I have annotated and am building a query with. I am getting an exception that looks like a bug as Postgres needs the AS keyword when aliasing a column. Am I missing some configuration setting?

The code is I use is:

EbeanServer server = Ebean.getServer(null);
Query trackQuery = server.createQuery(Track.class);
iterator = trackQuery.findList().iterator();

And the exception is:

javax.persistence.PersistenceException: Query threw SQLException:ERROR: syntax error at or near "c0" Query was:
select t.id c0, t.name c1, t.gid c2, t.length c3, t.artist c4
from track t

 
Rob 07 Mar 03:07
Fixed in HEAD

I have fixed this by defaulting to use the "AS" keyword for column alias' for all databases (not just Postgres).

As the note: the reason why we need column alias is for the case where concatinated keys are used (and we end up with the same columns references twice in the query). There may be a better long term solution.

Rob 15 Mar 02:35
Changed ...

I have changed the solution.

Ebean will now only use column alias' for column of imported concatinated keys - otherwise it does not use column alias'.

The reason I have done this is I find it much easier to take the sql and run it externally with the real column names.

If you need to have column alias on ALL columns you can do this by setting alwaysUseColumnAlias=true in ebean.properties:

##
## Use column alias on all columns
##
ebean.alwaysUseColumnAlias=true

##
## change the column alias prefix used
##
#ebean.columnAliasPrefix=as column_

woResponse

Upload a file