# Python extend

**URL:** <https://forum.inductiveautomation.com/t/python-extend/3274>\
**Category:** Ignition\
**Created:** [September 11, 2011, 9:40pm UTC](https://forum.inductiveautomation.com/t/python-extend/3274 "2011-09-11T21:40:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WKetcham](https://avatars.discourse-cdn.com/v4/letter/w/c57346/32.png) [@WKetcham](https://forum.inductiveautomation.com/u/WKetcham)\
**Post date:** [September 11, 2011, 9:40pm UTC](https://forum.inductiveautomation.com/t/python-extend/3274/1 "2011-09-11T21:40:06Z")

</div>

Can anyone tell me why this bit of code is not working?

[code]statdata = system.db.runPrepQuery(“select stationNum, stationPre, stationName from stationlist where stationnum = ?”,[stationNum],database = myDB)

rtData = system.db.runPrepQuery(“select %s , %s, %s, %s from WWater where t\_stamp Between ‘9/10/2011 0:00:00’ and ‘9/11/2011 0:00:00’” % (dailyRt,dailySrt,totRt,totSrt),database = myDB)

statdata.extend(rtData)[/code]

Running it gives me an attribute error on extend. With debug prints I have confirmed that the queries are returning the expected values now I just need to concatenate the lists.

My end game is to iterate through 22 stations and create a data set with 7 columns from the two queries above and 22 rows for a daily runtime report.

Thanks,

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 12, 2011, 1:16am UTC](https://forum.inductiveautomation.com/t/python-extend/3274/2 "2011-09-12T01:16:35Z")

</div>

You can’t use “extend” in the jython version hat IA is using. If you look at the Python 2.7 docs, they give a subsitute to extend: “Extend the list by appending all the items in the given list; equivalent to a[len(a):] = L”. Give that a shot.

Also, I do a lot of stuff like you are doing, and if you have 22 stations, you may want to use “GROUP BY” and reduce it to one or two queries. Just a thought.

---

<div class="post-metadata">

**Author:** ![WKetcham](https://avatars.discourse-cdn.com/v4/letter/w/c57346/32.png) [@WKetcham](https://forum.inductiveautomation.com/u/WKetcham)\
**Post date:** [September 13, 2011, 2:19am UTC](https://forum.inductiveautomation.com/t/python-extend/3274/3 "2011-09-13T02:19:23Z")

</div>

Thanks for the insight on extend. I am not having any luck with the equivalent either. I don’t know what my issue is. Hopefully it’s not fatigue induced idiocy. Out of curiosity, could you be more specific on the “GROUP BY”. I know what the GROUP BY statement is, but I am not seeing how exactly it gets me to my end game.

My historical data is stored in a single table, I am calculating the daily runtime by subtracting the MAX runtime from the MIN runtime in an sql statement with a WHERE clause of t\_stamp within a day.

I originally wrote out some inordinately long select statements which worked, but the single row couple hundred column dataset was not friendly for inserting them in a report using the reporting module (other than inserting them individually one at a time). I am now trying to create a dataset with a column for station name (from another table), daily runtime, daily start count, daily runtime per start, total runtime and total start count with a row for each station so I can group them in a table.

Any ideas would be great.

Thanks,

---

<div class="post-metadata">

**Author:** ![Step7](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Step7](https://forum.inductiveautomation.com/u/Step7)\
**Post date:** [September 13, 2011, 12:42pm UTC](https://forum.inductiveautomation.com/t/python-extend/3274/4 "2011-09-13T12:42:42Z")

</div>

I tried the extend equivalent, and it seems to work as intended. Aren’t you just concatenating two lists?

```auto
a=[1,2,3]
b=[4,5,6]
a[len(a):] = b
print a
```

Regarding the group by, I’m not sure what you are doing, so maybe it wouldn’t help. At a minimum though, I would get all the rows for all stations in a single query and iterate through them as needed instead of doing it one query at a time.
