I'm getting this 'program: Prelude.(!!): index too large' error for the following code:
select :: Field -> Field -> Table -> Table
select column_name column_value (header:t) = header:filterT t
where filterT = filter testR
field_idx = (elemIndices column_name header)!!0
testR r | r!!field_idx == column_value = True
testR r | otherwise = False
I suppose the error is regarding the following part of the code:
field_idx = (elemIndices column_name header)!!0
testR r | r!!field_idx == column_value = True
Does anyone know why it's giving me this error or how I could fix it?
I'm not sure what you're doing, but I hope you're aware, that !! is not a safe operation. an element with the index doesn't necessarily exist.
So you could get this error, if, for example, the header doesn't contain column_name.
Again, not sure what you exactly want to do, but if there's a chance there's no result, perhaps you want to wrap the result with Maybe?
Related
Having trouble with my query excluding results from a different query.
I have a table - Segment that I have already gotten entries from. It is related
to another table - Program, and I want to also run the same query on it but I want to exclude
any of the programs that were already found during the segment query.
When I try to do it, the list isn't allowed to be used in the comparison... See below:
query = "My Query String"
segment_results = Segment.objects.filter(
Q(title__icontains=query)|
Q(author__icontains=query)|
Q(voice__icontains=query)|
Q(library__icontains=query)|
Q(summary__icontains=query) ).distinct()
# There can be multiple segments in the same program
unique_programs = []
for segs in segment_results:
if segs.program.pk not in unique_programs:
unique_programs.append(segs.program.pk)
program_results = ( (Program.objects.filter(
Q(title__icontains=query) |
Q(library__icontains=query) |
Q(mc__icontains=query) |
Q(producer__icontains=query) |
Q(editor__icontains=query) |
Q(remarks__icontains=query) ).distinct()) &
(Program.objects.exclude(id__in=[unique_programs])))
I can run:
for x in unique_programs:
p = Program.objects.filter(id=x)
print("p = %s" % p)
And I get a list of Programs...which works
Just not sure how to incorporate this type of logic into the results
query...and have it exclude at the same time. I tried exclude keyword,
but the main problem is it doesn't like the list being in the query - I get an
error:
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'.
Feel like I am close...
The answer is simple, I was not comparing objects correctly in the filters, so
the correct statement would be:
program_results = (Program.objects.filter(
Q(title__icontains=query) |
Q(library__icontains=query) |
Q(mc__icontains=query) |
Q(producer__icontains=query) |
Q(editor__icontains=query) |
Q(remarks__icontains=query) )&
(Program.objects.exclude(id__in=Program.objects.filter(id__in=unique_programs))))
I want to run a query in Advanced Editor, only if the current date is NOT one of the following - 1, 5, 10, 15, 20, 25. Otherwise I dont want the query to run.
I have written the below but I am not getting anywhere very fast:
let
Output = if Date.Day (DateTime.LocalNow()) in (1,5,10,15,20,25) then null else
let
Source = PBILifts
in
#"PBILifts"
What am I doing wrong?
Cheers for all help
Edit: So based on suggestion by #Aleksei I tried below but it doesnt work:
let
output= if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then #table({},{}) else
Source = PBILifts
in
#"PBILifts"
I get the below error:
An error occurred in the ‘’ query. Expression.Error: The name 'Source' wasn't recognized. Make sure it's spelled correctly
Any further help please?
It's PQ, not SQL, so in (1,5,...) syntax is incorrect. Try something like this (assuming, your query's output is table):
= if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then #table({},{}) else YourQuery
or:
let
output = if List.Contains({1,5,10,15,20,25}, Date.Day(DateTime.LocalNow())) then #table({},{}) else PBILifts
in
output
I have a formula in my report to select a field based on requirements:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" and {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT})
else '0'
When I run the report it works ok until I try to load a specific page. When I try to load the page I get an error of 'The string is non numeric'. The formula is called in another formula:
{COR_TBL.COR_EXPECTED_DATE} + 2 + ToNumber({#FRM_NOTES})
I have ran the query on the server of:
SELECT * FROM EXT_TBL WHERE EXT_KEY_TYPE = "SO" AND EXT_ACTION_FLAG_9 = "Y";
This returned me two rows of data. I have narrowed it down to a specific entry that is causing the issue, but in the database the row has N in the field action flag 9 instead of Y so it shouldn't be throwing me the error in my report.
The action field 9 is flagged on only two records both of which contain a 7 in the EXT_TEXT feild so I have no idea why I am getting the error.
I also tried a nested if statement of:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" then (if {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT}))
else '0'
But it still gave me the same error.
Thanks
I was able to fix the issue by removing the nested if statement and just putting all the conditions in the original statement:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) AND {EXT_TBL.EXT_KEY_TYPE} = "SO"
AND {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
THEN {EXT_TBL.EXT_TXT} ELSE '0'
This seems to have fixed the issue.
Can I select a certain row/column combination in coldfusion without doing a query of queries? For example:
Some Query:
ValueToFind | ValueToReturn
String 1 | false
String 2 | false
String 3 | true
Can I somehow do #SomeQuery["ValueToFind=String 3"][ValueToReturn]# = true without doing a query of queries ? I know there's code out there to get a certain row by id, but I'm not sure how or if I can do it when I need a string as the ID
If this can't be done, is there a short hand way to set up a coldfusion function so I can use something like FindValue(Query, "String 3") and not have to use ?
You can treat a query column as an array.
yourRow = ArrayFind(queryName['columnName'], "'the value you seek'");
If you get a zero, the value you seekis not there.
Edit starts here:
For values of other columns in that row, simply use that variable.
yourOtherValue = queryName.otherColumnName[yourRow];
A small modification to Dan's code, you can find the column value using the code below
yourVaue = SomeQuery["ValueToReturn"][ArrayFind(SomeQuery['ValueToFind'], "String 3")]
Does someone can explain what is going on with my sql statement. Here is my code chunk.
for so in self.pool.get('sale.order').browse(cr,uid,so_id,context):
_logger.info("\n\n\t\t\t SALE ORDER ID %d"%(so.id))
confirmed_by = so.confirmed_by.id
_logger.info("\n\n\t\t\tconfirmed by %s"%(str(confirmed_by)))
rg_id = cr.execute("select rg.id from res_users ru,res_groups rg,res_groups_users_rel rgr
where ru.id = rgr.uid and rgr.gid = rg.id and ru.id = "+str(confirmed_by)+" and rg.name like 'Project Second User'")
_logger.info("\n\n\t\t\tRES GROUPS IDS %s"%(rg_id))
My confirmed by returns an id but I don't know why rg_id returns None when executed. When used in PgAdmin my query works fine.
Any help is very much appreciated.
This is how manage to solve the None issue:
cr.execute("select rg.id from res_users ru,res_groups rg,res_groups_users_rel rgr
where ru.id = rgr.uid and rgr.gid = rg.id and ru.id = "+str(confirmed_by)+" and rg.name like 'Project Second User'")
rg_id = cr.fetchall()
Now, my rg_id is returning either an id from a table res_groups or [] if there is no record found.