# QueryAddColumn

Adds a column to a query and populates its rows with the contents of a one-dimensional array.

## Method Signature

```
QueryAddColumn(query=[query], columnName=[string], datatype=[any], array=[array])
```

### Arguments

| Argument     | Type     | Required | Description                                                                                                 | Default  |
| ------------ | -------- | -------- | ----------------------------------------------------------------------------------------------------------- | -------- |
| `query`      | `query`  | `true`   | The query object to which the column should be added.                                                       |          |
| `columnName` | `string` | `true`   | The name of the column to add.                                                                              |          |
| `datatype`   | `any`    | `false`  | The column data type of the new column or the array to populate the column with a generic type of anything. | `object` |
| `array`      | `array`  | `false`  |                                                                                                             | `[]`     |

## Examples

### Tag Example

```java
<!--- Make a query. ---> 
 <bx:set myQuery = queryNew( "" ) > 
  <!--- Create an array. ---> 
 <bx:set FastFoodArray = arrayNew( 1 ) > 
 <bx:set FastFoodArray[ 1 ] = "French Fries" > 
 <bx:set FastFoodArray[ 2 ] = "Hot Dogs" > 
 <bx:set FastFoodArray[ 3 ] = "Fried Clams" > 
 <bx:set FastFoodArray[ 4 ] = "Thick Shakes" > 
 <!--- Use the array to add a column to the query. ---> 
 <bx:set nColumnNumber = queryAddColumn( myQuery, "FastFood", "VarChar", FastFoodArray ) > 
 <bx:dump var="#myQuery#"/> 
```

### member syntax example

add a column to a query using member syntax

[Run Example](https://try.boxlang.io/?code=eJxLys%2FPLlawVSgsTS2q9Est11BQykzRKcksyUlV0gGy80pS01OLdMoSi5IzEouUFDStuZJAWvQSU1Kc83NKc%2FOAOhJLSzLyi0DqYep0FKJjQWrLizJLUl1Kcws0FMDaQGIAukUlgg%3D%3D)

```java
books = queryNew( "id,title", "integer,varchar" );
books.addColumn( "author", "varchar", [] );
writeDump( books );

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJwrLKpUsFUoLE0tqvRLLddQUEpMTNRJSkpSUtC05goECTumpATlA2UKgSphYsGpJc6pOTlgQR2wHiUgZahnqIRLCchIsBIjckw2ImyyEZrJzvk5pbl5MEXJyclARTmZxSUh%2BY5FRYmVQJ8a6xnqGIN14daXkpICMjwzryQ1PbUIwwgToBEmcCPKizJLUl1KcwvAuvWc%2FX1Cff18PINDQJIAVuJqfw%3D%3D)

```java
qry = queryNew( "aaa,bbb" );
QueryAddRow( qry );
QuerySetCell( qry, "aaa", "1.1" );
QuerySetCell( qry, "bbb", "1.2" );
QueryAddRow( qry );
QuerySetCell( qry, "aaa", "2.1" );
QuerySetCell( qry, "bbb", "2.2" );
QueryAddColumn( qry, "ccc", listToArray( "3.1,3.2" ) );
QueryAddColumn( qry, "ddd", "integer", listToArray( "4.1,4.2" ) );
writeDump( qry.COLUMNLIST );

```

## Related

* [QueryAddRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryaddrow)
* [QueryAppend](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryappend)
* [QueryClear](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryclear)
* [QueryColumnArray](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumnarray)
* [QueryColumnCount](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumncount)
* [QueryColumnData](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumndata)
* [QueryColumnExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumnexists)
* [QueryColumnList](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycolumnlist)
* [QueryCurrentRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querycurrentrow)
* [QueryDeleteColumn](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querydeletecolumn)
* [QueryDeleteRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querydeleterow)
* [QueryEach](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryeach)
* [QueryEvery](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryevery)
* [QueryFilter](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryfilter)
* [QueryGetCell](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querygetcell)
* [QueryGetResult](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querygetresult)
* [QueryInsertAt](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryinsertat)
* [QueryKeyExists](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querykeyexists)
* [QueryMap](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querymap)
* [QueryNew](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querynew)
* [QueryNone](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querynone)
* [QueryPrepend](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryprepend)
* [QueryRecordCount](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrecordcount)
* [QueryRecordCount](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrecordcount)
* [QueryReduce](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryreduce)
* [QueryRegisterFunction](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryregisterfunction)
* [QueryReverse](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryreverse)
* [QueryRowData](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrowdata)
* [QueryRowSwap](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryrowswap)
* [QuerySetCell](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysetcell)
* [QuerySetRow](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysetrow)
* [QuerySlice](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryslice)
* [QuerySome](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysome)
* [QuerySort](https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/querysort)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/query/queryaddcolumn.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
