> For the complete documentation index, see [llms.txt](https://wiki.robmurtagh.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.robmurtagh.com/aws/athena.md).

# Athena

## Add columns

```sql
ALTER TABLE db.table ADD COLUMNS (column_name string)
```

## Change column type (doesn't work?!)

```sql
ALTER TABLE db.table CHANGE column_name column_name timestamp;
```

## List all partitions

```sql
SHOW PARTITIONS appsflyer_stream
```

## Special characters

```sql
  SELECT column_name_1, "column-name-2", column_name_3, ##
  FROM db.table
  WHERE column_name_3 is not null
  ORDER BY timestamp_column DESC;
```

## Using a substring

```sql
SELECT event_name, substr(timestring, 1, 10) as datestring, count(##) AS count
FROM stream
WHERE test_mode != 'true' AND event_name = 'event_a'
GROUP BY event_name, substr(timestring, 1, 10)
ORDER BY datestring DESC
```

## Between timestamps

```sql
WHERE timestamp BETWEEN timestamp '2017-06-13 15:50:00.000' AND timestamp '2017-06-13 16:52:29.000'
```

## Null handling

```sql
WHERE column IS null
```

## Casting

```sql
SUM(CAST(sysvar_sales AS Double)) AS Sales
```

## Literals

```sql
true AS picnic_install
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://wiki.robmurtagh.com/aws/athena.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
