[Dbix-class] How do I select bound functions with as 'as' name in the column

Peter Rabbitson rabbit+dbic at rabbit.us
Fri Mar 8 14:18:24 GMT 2013


On Fri, Mar 08, 2013 at 02:05:19PM +0000, Robert Rothenberg wrote:
> 
> I am trying to run a DBIx::Class query on a PostGIS function with binders,
> with the attributes of the search query having something like:
> 
>  {
>   'as' => [
>   'id',
>   'name',
> 	  'location',
> 	  'distance_from_location'
> 	  ],
> 	  'order_by' => ['distance_from_location'],
> 	  'join' => [],
> 	  'select' => [
> 	      \ 'me.id::int',
> 	      'me.name',
> 	      {
> 		  'ST_AsText' => 'me.location'
> 	      },
> 	      \ [
> 		  'ST_Distance(me.location,ST_GeomFromText(?, 27700))',
> 		  [
> 		   'location',
> 		   'POINT(400928 298992)'
> 		  ]
> 	      ]
> 	  ]
>   }
> 
> This worked. Then, for reasons I don't understand, stopped working.

Could you recall what you did when it stopped working? Upgrade or anything?

> So how do I specify the 'as' attribute for bound functions?

What you have above is a literal chunk of SQL - stuff that will be passed
to the RDBMS directly. Simply change

  'ST_Distance(me.location,ST_GeomFromText(?, 27700))'
to
  'ST_Distance(me.location,ST_GeomFromText(?, 27700)) AS distance_from_location'


Though I still would like to find out how that ever worked.

Cheers




More information about the DBIx-Class mailing list