Adding a temporary column to a db_select query I'd like to add a temporary column with a fixed value to a database query. Eg a column called 'type' with a value of 'thing' for every result. I have tried using the addExpression and addField functions to do this but I'm not getting the right result.

Is this possible using db_select? I've tried the following:

$query = db_select('people', 'p')
   -&gt;fields('p', array('id', 'date'));
$query-&gt;addField(':val AS type', array(':val'=&gt;'thing'));


However this is executing the following query:

SELECT p.id AS id, p.date AS date
FROM 
people p


I suppose I'm trying to get drupal to do:

SELECT p.id AS id, p.date AS date, 'thing' as type
FROM 
people p
You just need to use an expression, e.g.

$query = db_select('people', 'p')
  -&gt;fields('p', array('id', 'date'));

$query-&gt;addExpression(':val', 'type', array(':val' =&gt; 'thing'));


Gives:

SELECT p.id AS id, p.date AS date, :val AS type
FROM 
{people} p


The replacement for :val will be injected when you execute the query.