jcm | 29 Apr 2012 16:11
Favicon

Column aliases

I've not had much luck finding a way to alias column names.

(clsql:select
		  [response_date] [comment] [val]
		  :from *comments-view*
		  :where [and [= [survey_id] tool] [null [question_id]]])

I've tried

[response_date date]

but I see no difference in the column names or any error.

How can I do this?
Russ Tyndall | 30 Apr 2012 16:38
Favicon
Gravatar

Re: Column aliases

Hello,

There is not an easy syntax way of creating aliases (yet),
though good / reasonable patches for this would be accepted.  You will
also have better luck if you include what backend(s) you are having
issues with.

  * [response_date date] will create the column name response_date.date

  * You can check the output of a sql expression by calling
(clsql-sys:sql [response_date date] )

  * You can always ensure that your exact desired output is emitted by
using the sql-expression :string function. This is probably the easiest 
path.
(clsql-sys:sql-expression :string "response_date as date")

  * You *could* use a sql-ident-table directly though this is the wrong
type and I cannot guarantee it would work in all forms, and it is not
supported by the syntax either. This seems unideal, but might solve your
issue

eg>(clsql-sys:sql
      (clsql:sql-expression :table "foo.response_date" :alias "date" ))
=> "\"foo.response_date\" \"date\""

  * You could use clsql:query instead and enter the whole query as a
string

  * This form seems like it should work, but doesnt (because it creates an
(Continue reading)


Gmane