tracker issue : CF-3499033

select a category, or use search below
(searches all categories and all time range)

New function request: valueArray() to complement valueList()

| View in Tracker

Status/Resolution/Reason: Closed/Fixed/

Reporter/Name(from Bugbase): Adam Tuttle / Adam Tuttle (Adam Tuttle)

Created: 02/12/2013

Components: Language

Versions: 10.0

Failure Type: Enhancement Request

Found In Build/Fixed In Build: Final / Raijin

Priority/Frequency: Trivial / Unknown

Locale/System: English / Platforms All

Vote Count: 6

Listed in the version 2016.0.0.297996 Issues Fixed doc
Verification notes: verified_fixed on August 26, 2019 using build 2016.0.01.298513
Often I find myself looking to get all of the values for a single column of a query result, as an array. Right now I generally use this syntax:


This is generally functional, except when the column in question is free-form text entered by users and could contain your delimiter, even if you use a custom delimiter like a pipe.

Aside from the above edge case, string manipulation is generally regarded as slow, at least when compared to other data structures like arrays and queries.

I'd like to see the addition of a new function, valueArray() that returns an array of the column values from a query object, exactly like valueList -- except there will be no need for delimiters. This would eliminate all room for error with delimiters, and could potentially make dealing with large datasets much faster.

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	3499033

External Customer Info:
External Company:  
External Customer Name: Adam.Tuttle
External Customer Email:  
External Test Config: My Hardware and Environment details: N/A



I put this idea in Adam's head so I vote 'yes' and also vote for royalties for my brilliant idea. :)
Vote by External U.
16338 | February 12, 2013 10:12:17 AM GMT
i, too, appreciate a good array every now and then.
Vote by External U.
16339 | February 12, 2013 10:16:03 AM GMT
There are several ways to do this currently that are undocumented. You could make use of this functionality as the implementation for valueArray() or even just document and plan to support the existing functionality in future releases. For example: a = []; a.addAll( query['column'] );
Comment by External U.
16309 | February 15, 2013 08:41:03 AM GMT
+1, I'd use this often. 1234567890
Vote by External U.
16340 | May 21, 2014 02:07:58 AM GMT
+1 for some sort of solution here, if not exactly the mooted one
Vote by External U.
16341 | December 09, 2014 02:42:39 AM GMT
This is flagged as "to fix". When is this scheduled to happen?
Comment by External U.
16310 | December 09, 2014 02:43:02 AM GMT
+1 "That man is playing Galaga! Thought we wouldn't notice. But we did." - Tony Stark, The Avengers
Vote by External U.
16342 | December 09, 2014 08:59:26 PM GMT
Seems Railo deprecated this function some time back, and replaced it with a more clearly named queryColumnData() function. If this functionality is implemented in ColdFusion, maybe queryColumnData should be used for the function name. See!topic/railo/udy2hQvnnrU for a recent discussion about valueArray() and queryColumnData().
Comment by External U.
16311 | December 09, 2014 09:09:25 PM GMT
Agreed. And don't just get fixated on the old-school headless functions; we should be focusing on member functions in the language these days. myQuery.columnData("column"). That said, do we need a function? Can support for myQuery["myColumn"] being a reference to the entire column - and that being array-compatible - just be cemented? That'd be better, wouldn't it?
Comment by External U.
16312 | December 10, 2014 01:23:31 AM GMT
I would be very happy if query["column"] returned an array.
Comment by External U.
16313 | December 10, 2014 08:10:34 AM GMT
+1. Please remove the 25 char max. Give me source code access and I'll fix it myself in 2 seconds.
Vote by External U.
16343 | January 19, 2015 02:47:20 PM GMT
Adobe, hello? (see my question from close to a year ago)
Comment by External U.
16314 | September 24, 2015 03:00:29 AM GMT
Hi all, I also like the idea of q["col"] returning an array, but it looks like it might break existing code? <cfset q = queryNew("myColumn", "", [["a"]])> <cfset foo = q["myColumn"]> <cfoutput>#foo#</cfoutput> <cfset q = queryNew("myColumn", "", [["a"]])> <cfloop query="q"> <cfset foo = q["myColumn"]> <cfoutput>#foo#</cfoutput> </cfloop> Both currently return "a" but would throw an exception? Thanks!, -Aaron
Comment by External U.
16315 | September 26, 2015 09:53:06 PM GMT
How about q.valueList("myColumn") and q.valueArray("myColumn")? I actually thought q.valueList() already worked, but it doesn't. Thanks!, -Aaron
Comment by External U.
16316 | September 26, 2015 09:55:43 PM GMT
Regarding thinking q.valueList() was already implemented: I see that's already been filed as CF-3864595. Thanks!, -Aaron
Comment by External U.
16317 | September 26, 2015 10:02:31 PM GMT
There's actually this functionality already, though don't think it is documented (haven't found it anywhere and just accidentally stumbled on it). The query's column object has a toArray() method (going back at least to acf10)
Comment by External U.
16318 | October 01, 2015 01:16:36 PM GMT
Does that not return a Java array, not a CFML array though? (not in a positive to test right now).
Comment by External U.
16319 | October 01, 2015 01:20:12 PM GMT
It does, which is better than a list. If you listToArray() a valueList() it will remove empties unless you also add the delimiter and includeEmptyFields arguments.: listToArray( valueList( query.column ), ",", true ) as apposed to query.column.toArray() I know there are some issues with iterating java arrays in acf9, but not sure if there are any known issues using a java array in acf10+. That being said, if you *don't* want empty values in your array, then a valueArray() type function that has an argument to include/exclude empties would be awesome. What would be even awesomer is if instead of adding valueArray(), adobe overloads .toArray() with a method that has an include empty toggle. Then it'd be more natural to say query.column.toArray(false). In the same vein, the query object should also have a toArray() method which would output an array of structs.
Comment by External U.
16320 | October 01, 2015 01:50:22 PM GMT
Hi Abram, I like those ideas. +1 to query.column.toArray() and the parameter to include/exclude empties (and then query.column.toList()). I see #CF-3041672 was a CF9 java array iteration issue in CF9 but runs fine in CF11 (didn't test CF10). +1 to query.toArray() to return an array of structs. Thanks!, -Aaron
Comment by External U.
16321 | October 05, 2015 01:08:18 AM GMT
Abram, I'm not arguing the case of array vs list, I'm arguing that what is returned from .toArray() is not a CFML data type, so it's not an appropriate *CFML* solution. Java arrays are immutable, so the resultant value won't behave "predictably" with any array operation which needs to change the array. It's just a piss-poor way of dealing with the issue, when it'd be easy enough to do it properly. Don't encourage the ColdFusion Team to do subpar work. They don't need that sort of encouragement. Do it properly, or don't do it at all.
Comment by External U.
16322 | October 05, 2015 03:49:25 AM GMT
Ah, Adam makes a good point. So I like q.valueList("myColumn") and q.valueArray("myColumn"). Thanks!, -Aaron
Comment by External U.
16323 | October 08, 2015 01:04:32 AM GMT
Well if it's a Query method, yeah, it'd need to be that. Or QueryColumn could be promoted to being "a thing", in which case myQuery.someColumn.toArray(). However if that approach was taken then simply promote QueryColumn being being "a thing", and have it implement the Array interface directly. It's analogous enough to an array (sequential set of elements) for that to be a sensible approach. TBH, I dunno whether CFML should be adding any more procedural functions; instead it should be be adding methods and applying standardised interfaces to its object types.
Comment by External U.
16324 | October 08, 2015 01:26:17 AM GMT
We are thinking of enabling only ValueArray as member function considering ValueList has it's limitations around the delimiter logic. Any cases where List is preferable compared to Array ?
Comment by Himavanth R.
16325 | October 15, 2015 03:01:47 AM GMT
Nope. And anyhow, if anyone wants a list they can go: query.column.toArray().arrayToList() This is perhaps a point of clarification needed here. What exactly are you going to implement: query.column.valueArray() query.valueArray("column") If you're not positioning this as an parallel to valueList(), and only implementing the object method, then .toArray() would be a better name, and follow the first example above: queryColumn.toArray() (where queryColumn is any expression which references a query column, eg: query.column, query["column"], etc) However this raises a broader issue that query columns ought better perhaps implement the entire array "interface". Similar to this ticket for entire queries: This would help make CFML more predictable.
Comment by External U.
16326 | October 15, 2015 03:26:29 AM GMT
Hi Himavanth, Please always keep the language predictable. If you don't want to add .valueList(), then please also deprecate valueList(). I agree array is preferable over list. I just oppose the language becoming messier. Ex: <cfdirectory action="list"..> returning a list but directoryList() returning an array. Ex: cfinvokeargument() isn't supported as a script replacement for <cfinvokeargument>. Ex: cfdocument supports any HTML in a header/footer, but cfhtmltopdf supports only like 5 HTML tags. Ex: <cfpdf action="archive" only works if the PDF to be archived was created w/ cfdocument, but fails if the PDF was created w/ cfhtmltopdf. Ex: <cftrace> and trace() behave inconsistently (ticket CF-3811003). Ex: Referencing an unset query cell behaves inconsistently (ticket CF-4073791). Those are just the items off the top of my head. I'm sure I could find more. I just want consistency in language. Thanks!, -Aaron
Comment by External U.
16327 | October 15, 2015 12:59:03 PM GMT
Ex: <cfdirectory action="list"..> returning a list should've been Ex: <cfdirectory action="list"..> returning a query
Comment by External U.
16328 | October 15, 2015 12:59:38 PM GMT
Hi Adam, I agree that the queryColumn should be any expression that references a query column. By query columns implementing an array interface, does that also mean the following would break instead of returning "a b"? <cfset q = queryNew("myColumn", "", [["a"],["b"]])> <cfloop query="q"> <cfset foo = q["myColumn"]><!--- would this also now return an array, and break? ---> <cfoutput>#foo#</cfoutput> </cfloop> Thanks!, -Aaron
Comment by External U.
16329 | October 15, 2015 01:13:15 PM GMT
Added ValueArray headless function and also as a member function for query object since ValueArray made more sense than ValueList It takes the query object and columnName string and returns an array. This is more intuitive function signature though it is inconsistent with ValueList's signature. valuearray(q, "myColumn") q.valueArray('myColumn')
Comment by Himavanth R.
16330 | October 20, 2015 04:33:24 AM GMT
Hi Himavanth, Can you please deprecate headless function valueList(), since member function .valueList() isn't being added? Either both should exist, or neither should exist. No inconsistencies please. Thanks!, -Aaron
Comment by External U.
16331 | October 21, 2015 03:05:20 PM GMT
Point noted Aaron. We are reviewing this.
Comment by Himavanth R.
16332 | October 22, 2015 11:35:30 PM GMT
Below headless function & member function have been implemented and tested in latest build of CF12 . valuearray(q, "myColumn") query.valueArray('myColumn') Hence closing the bug .
Comment by Nitin K.
16333 | November 12, 2015 12:31:59 PM GMT
Hi Nitin, So, for consistency, are you deprecating valueList() or adding .valueList()? Thanks!, -Aaron
Comment by External U.
16334 | November 15, 2015 03:57:22 AM GMT
Comment by External U.
16335 | December 04, 2015 05:11:09 AM GMT
I also forgot .quotedValueArray(). So will quotedValueList() be deprecated in favor of .quotedValueArray()? Thanks!, -Aaron
Comment by External U.
16336 | December 08, 2015 08:17:10 AM GMT
Aaron , Please find the bug number for your request . Tracking Bug #CF-4098246
Comment by Nitin K.
16337 | December 10, 2015 12:44:07 AM GMT
Hi Adobe, I've verified this is fixed in CF2016 Update 1 (build 2016.0.01.298513), well except for CF-4098246 and my unanswered questions therein from a few years ago. Thanks!, -Aaron
Comment by Aaron N.
31219 | August 26, 2019 05:45:18 AM GMT