Answers.Body: <p>There was a long discussion about this at <a href="https://lab.civicrm.org/dev/core/-/issues/3738" rel="nofollow noreferrer">https://lab.civicrm.org/dev/core/-/issues/3738</a></p>
  <p>which resulted in a new <code>$result-&gt;rekey()</code> method added to the next beta (5.74).</p>
  <p>See <a href="https://github.com/civicrm/civicrm-core/pull/29714" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/pull/29714</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-20T16:16:03.457Z
Answers.Text: Okay so that at least answers my question: "No you can not do that (yet)"!
Answers.UserDisplayName: jsherk
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-04-20T12:47:32.850Z
Answers.LastActivityDate: 2024-04-20T12:47:32.850Z
Answers.UserDisplayName: Coleman
Body: <p>I want to rename the column/fields I am retreiving in the SELECT statement. Best way to ask this is by showing an example...</p>
  <p>Given this select call:</p>
  <pre><code>$contacts = civicrm_api4('Contact', 'get', [
    'select' =&gt; [ 'id', 'display_name', ],
    'limit' =&gt; 5,
    'checkPermissions' =&gt; TRUE,
  ]);
  </code></pre>
  <p>Which returns object with:</p>
  <pre><code>[{&quot;id&quot;: 2983,&quot;display_name&quot;: null },]
  </code></pre>
  <p>But what if I want to rename the 'display_name' field as something else (say 'dname'), to get a result like this:</p>
  <pre><code>[{&quot;id&quot;: 2983,&quot;dname&quot;: null },]
  </code></pre>
  <p>I tried both the following but it does not work:</p>
  <pre><code>  'select' =&gt; [ 'id', 'display_name AS dname', ],
    'select' =&gt; [ 'id', 'display_name as dname', ],
  </code></pre>
  <p>Is there a way to do this, or is it not possible with the API call?</p>
  <p>Thanks</p>
  
Tags: <wordpress><contacts><api><apiv4>
Title: Can rename(AS) a column/field from SELECT using APIv4
ThreadText: # Can rename(AS) a column/field from SELECT using APIv4
  
  (Asked by: username_0 on 2024-04-20)
  
  I want to rename the column/fields I am retreiving in the SELECT statement. Best way to ask this is by showing an example...
  Given this select call:
  $contacts = civicrm_api4('Contact', 'get', [
    'select' => [ 'id', 'display_name', ],
    'limit' => 5,
    'checkPermissions' => TRUE,
  ]);
  
  Which returns object with:
  [{"id": 2983,"display_name": null },]
  
  But what if I want to rename the 'display_name' field as something else (say 'dname'), to get a result like this:
  [{"id": 2983,"dname": null },]
  
  I tried both the following but it does not work:
    'select' => [ 'id', 'display_name AS dname', ],
    'select' => [ 'id', 'display_name as dname', ],
  
  Is there a way to do this, or is it not possible with the API call?
  Thanks
  
  **Tags:** wordpress, contacts, api, apiv4
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-04-20. Score: 3 | Accepted answer
  
  There was a long discussion about this at <https://lab.civicrm.org/dev/core/-/issues/3738>
  
  which resulted in a new `$result->rekey()` method added to the next beta (5.74).
  
  See <https://github.com/civicrm/civicrm-core/pull/29714>
  
  > **Comments:**
  > **username_0**: Okay so that at least answers my question: "No you can not do that (yet)"!  
  
  ---
  
  