Closed rorosentrater closed 5 years ago
OK after doing some more research I realize now that this a bit of a loaded question. I neglected the fact that most people doing this are probably aggregating things too. So for example, unless you have DB constraints you could get more than 1 result querying whatever you set as your "rows" and "column" parameters. In that case, I get the need for aggregation because the collection of those matching values need to be distilled down into 1 so that a single value can be used for the cell.
But say you did have DB constraints in place. Meaning that you only ever got 1 result for each "rows" + "column" query, is there no easy way to display just that value?
For this i am using string aggregation from postgresql.
I found a hack.
pivot_table = pivot(SkuData, 'sku', 'label', 'value', aggregation=Max)
Since my DB constraints ensure there is only ever 1 result, you can safely use the Max or Min aggregate which (since it's the only value) will give you the actual value of the matching field (normally fieldS), with no type conversion. I have not tested this with all table data types though so your mileage may vary.
Hi, I am using this library to pivot my tables, but without any sort of data aggregation. I noticed that when I use a CharField as the 4th parameter (data) I get some unexpected type conversion in my results. Take the following sample data. This is what my DB looks like:
When I run this command:
pivot_table = pivot(SkuData, 'sku_id', 'label', 'value')
The output seems to be forcing all of my strings into a double:
The issue is especially visible for the value of "power cord." which is changed from the string "3 prong" to the double 3.0.
Is this intended functionality?