# Perspective PowerChart export with annotations?

**URL:** <https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 30, 2024, 1:27am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112 "2024-05-30T01:27:55Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![taohongyu88](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@taohongyu88](https://forum.inductiveautomation.com/u/taohongyu88)\
**Post date:** [May 30, 2024, 1:27am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/1 "2024-05-30T01:27:55Z")

</div>

Version: 8.1.24  
In PowerChart I add some annotations in chart.  
When I export to CSV, I want to export annotations together.

 ![a3268d2a44108c6caa51cd6cdb23b58](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/2/d25e61c74e39d888116c5d770205e7e4c89c764e.png)

 ![a0f996333b54826eecdc9f9e701766d](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/e/ce1953b97fb3c2227bdf476b4b367344ba6bce1f.png)

 ![87674c7cd81b6da78df015396763b5c](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/4/94894f8480422fc02dcfae0c05628258fcbfc8dd.png)

How to resolve it?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 30, 2024, 5:53pm UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/3 "2024-05-30T17:53:32Z")

</div>

Don't write a manual query against historian tables.

Use `system.tag.queryTagHistory` and `system.tag.queryAnnotations`:

> **[system.tag.queryTagHistory | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagHistory)**
>
> Issues a query to the Tag Historian.

> **[system.tag.queryAnnotations | Ignition User Manual](https://www.docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryAnnotations)**
>
> Queries annotations stored in the Tag History system for a set of paths for a given time range.

Then join your datasets with scripting, format to CSV, then use `system.perspective.download` to prompt the user to download the file.

There's no functionality built in to the power chart to do this, probably because of the 'line up the timestamps' problem Transistor alluded to.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 30, 2024, 6:10pm UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/4 "2024-05-30T18:10:03Z")

</div>

> [@paul-griffith](#):
>
> Use `system.tag.queryTagHistory` and `system.tag.queryAnnotations`:

That's a much better idea. I had seen those in the docs but never had occasion to use and forgot about them. I've deleted my answer lest I lead someone astray.

---

<div class="post-metadata">

**Author:** ![taohongyu88](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@taohongyu88](https://forum.inductiveautomation.com/u/taohongyu88)\
**Post date:** [June 4, 2024, 9:10am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/5 "2024-06-04T09:10:38Z")

</div>

I already query the result in Laboratory Database .

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/d/9d9e796c38aa266708e806755878580a8069f309.png)

```python
paths = [u"[Laboratory]TestTag222"]
startTime=system.date.addDays(system.date.now(), -30)
endTime = system.date.now()
types = ['note']
annotations=system.tag.queryAnnotations(paths, startTime, endTime,types)
for item in annotations:
    print item
    print item.data

```

If I want to query the result in other Database ,How to resolve?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/6/76f99f482573683aed12bff07b905eb24ddfadf8.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 4, 2024, 9:38am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/6 "2024-06-04T09:38:17Z")

</div>

You are running two queries which are returning datasets with different numbers of columns and different types.

You will need to write a script to combine the datasets. The "output" dataset will have to have all the columns of both tables but you will have to decide how to merge the historian _t\_stamp_ column and, presumably, the _start\_time_ column of the annotations table.

Then you will loop through the first dataset and copy the columns into the appropriate output columns and do the same with the second dataset. You would then have to sort by _t\_stamp_ or do that in Excel.

---

<div class="post-metadata">

**Author:** ![taohongyu88](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@taohongyu88](https://forum.inductiveautomation.com/u/taohongyu88)\
**Post date:** [June 4, 2024, 10:13am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/7 "2024-06-04T10:13:54Z")

</div>

Maybe I have to use sql ,not use system.tag.queryAnnotations.

```python
SELECT a.tagid , a.start_time ,a.end_time ,a.type, a.datavalue , t.id, t.tagpath FROM sqlth_annotations as a  
left join sqlth_te as t on a.tagid=t.id

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/6/e692e89dd3260d1b6a9d270af906fb7e82cf5e35.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 4, 2024, 10:16am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/8 "2024-06-04T10:16:51Z")

</div>

That doesn't give you the history data. You only get the annotations.

---

<div class="post-metadata">

**Author:** ![taohongyu88](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@taohongyu88](https://forum.inductiveautomation.com/u/taohongyu88)\
**Post date:** [June 4, 2024, 10:29am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/9 "2024-06-04T10:29:20Z")

</div>

How to union many months data from different table（sqlt\_data\_1\_2024\_06，sqlt\_data\_1\_2024\_05） by the startTime and endTime?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 4, 2024, 10:31am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/10 "2024-06-04T10:31:31Z")

</div>

Both Paul and I have advised you not to do that. Use Ignition's functions and script the combination of the data.

---

<div class="post-metadata">

**Author:** ![taohongyu88](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@taohongyu88](https://forum.inductiveautomation.com/u/taohongyu88)\
**Post date:** [June 4, 2024, 10:36am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/11 "2024-06-04T10:36:35Z")

</div>

> [@taohongyu88](#):
>
> `system.tag.queryAnnotations`

But system.tag.queryAnnotations can't Specify the database

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 4, 2024, 10:49am UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/12 "2024-06-04T10:49:07Z")

</div>

Neither can [system.tag.queryTagHistory | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/appendix/scripting-functions/system-tag/system-tag-queryTagHistory).

I would expect that both find the database connection from the tag history definition. See [Tag Properties | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.1/platform/tags/tag-properties#history-properties).

---

<div class="post-metadata">

**Author:** ![taohongyu88](https://avatars.discourse-cdn.com/v4/letter/t/f05b48/32.png) [@taohongyu88](https://forum.inductiveautomation.com/u/taohongyu88)\
**Post date:** [June 4, 2024, 1:21pm UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/13 "2024-06-04T13:21:56Z")

</div>

Project set Database ----Laboratory

 ![c4c17e2665b003f9789a10b4ce76ae1](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/d/2d4e0d06a91cb872c67167d051de9e1fd2b7f002.png)

But I add tag History set Database --- postgres

 ![7e7b5db882d996fdc5287d3c6937d79](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/9/c96850c53582c2cf39a1c9255db7af6de74aa712.png)

`annotations=system.tag.queryAnnotations(paths, startTime, endTime,types)`  
Only query the tag's history Annotation of Laboratory, can't query the tag's history Annotation of postgres?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 4, 2024, 1:42pm UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/14 "2024-06-04T13:42:16Z")

</div>

Tags are outside any project. They don't use your project's database setting. You've told the tag to use the `postgres` storage provider. That's where the annotations must go, too.

Ignition's API functions will use the correct database based on the tag settings.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 4, 2024, 1:47pm UTC](https://forum.inductiveautomation.com/t/perspective-powerchart-export-with-annotations/91112/15 "2024-06-04T13:47:23Z")

</div>

Tips:

1. "postgres" is **not** a good name for a connection. It is the name of the database engine. Your Connect URL probably looks something like this:  
`jdbc:postgresql://host:port/YourDatabaseName`  
and you should set the connection name to `YourDatabaseName` to make it obvious which database the connection connects to.
2. Then modify the Storage Provider in all the tags that use it. (You can multi-select and edit them all at once.)

You may be able to avoid losing history like this:  
3. Create a new connection to `jdbc:postgresql://host:port/YourDatabaseName` (the same database as before) and give it a sensible name.  
4. Then convert your tags to use the new connection. All the data will go to the same database.  
5. Disable the original `postgres` database connection and confirm that history and annotations are still being recorded.  
6. If successful then delete the `postgres` connection.

That will make it much clearer to whoever has to maintain the system - even if it is you.
