Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Column aliasing in SELECT statements doesn't work with SQuirrel SQL + Firebird

I tried add an column alias in SELECT statement using SQuirrel SQL 3.4 + Firebird 1.5 + Driver JDBC Jaybird 2.2.[0|1] (JVM 1.7.0_03), but doesn't work. The column aliased appears with the original name of column. In another tool (DBExpert) the same statement works fine.

Statement: SELECT column1 AS alias1, column2 FROM table;
Resultant columns name in SquirrelSQL: column1 - column2
Resultant columns name in DBExpert: alias1 - column2

Tried add ' and " around alias name, but also not work.

Someone have an idea?

Edit: I updated the JDBC Jaybird driver to 2.2.1 version (released Sept/30) and the problem remains.

Edit 2: Problem fixed!

The problenm is caused by default preferences of Squirrel SQL.

To fix it, go to "File" -> "Global Preferences", in tab "Data Type Controls" find "General (applies to all types)" and mark the combo-box "Use column labels instead of column names in result headers".

See the screenshot: http://i1-win.softpedia-static.com/screenshots/SQuirrel-SQL-Client_4.png?1345342622

Enjoy.

like image 790
xthiago Avatar asked Oct 03 '12 13:10

xthiago


People also ask

Can we use column alias in SELECT statement?

Alias is used to give a temporary name(only for the duration of the query) to the column or table in order to make the column name or table name more readable. It does not change the name of the column permanently.

What is the proper syntax for aliasing a field in SQL?

The basic syntax of a table alias is as follows. SELECT column1, column2.... FROM table_name AS alias_name WHERE [condition];

How does aliasing work in SQL?

SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. An alias only exists for the duration of that query. An alias is created with the AS keyword.

What type of SQL does SQuirreL use?

Unsourced material may be challenged and removed. The SQuirreL SQL Client is a database administration tool. It uses JDBC to allow users to explore and interact with databases via a JDBC driver. It provides an editor that offers code completion and syntax highlighting for standard SQL.


2 Answers

The problem is due to confusion in the JDBC specs (at least historically) and a change in Jaybird with regard to what it reports as columnNames and columnLabels in the resultset metadata. As far as I am aware in JDBC 2.0 and earlier, the distinction between columnName and columnLabel was not well defined, so in almost all cases getColumnName() returned the same value as getColumnLabel() (ie the AS alias if specified).

With JDBC 3.0 a sharper distinction was made: the columnName was to be the name of the underlying column in a table (if any), the columnLabel is the AS-alias if specified and otherwise the columnName. Jaybird 2.1.6 and earlier used to return the same value for getColumnLabel() and getColumnName() (ie the columnLabel), this was changed in Jaybird 2.2.

Apparently Squirrel defaults to the non-JDBC compliant option of columnName, instead of columnLabel. As you already found out: there is an option to get it to use the columnLabel instead. The other option you have is to use Jaybird 2.2.1 or higher and add the connection property columnLabelForName=true.

like image 134
Mark Rotteveel Avatar answered Sep 23 '22 19:09

Mark Rotteveel


In Squirrel this needs to be set up on:

File > Global Preferences > Data Type Controls > Check: Use column labels instead of column names in result headers

like image 27
Joabe Lucena Avatar answered Sep 24 '22 19:09

Joabe Lucena