FQL subquery breaks top query and never returns - facebook-fql

We have a FQL query that used to work and stopped somewhere around Oct 16. No help from Facebook on this.
This code used to work:
SELECT object_id, metric, end_time, period, value
FROM insights
WHERE object_id IN
(
SELECT page_id
FROM page_admin
WHERE uid=123
AND page_id<>456
AND page_id<>789
)
AND metric="page_audio_plays"
AND end_time=end_time_date("2011-11-11" )
AND period=86400
If I run the inner Select, it returns a large list of page_id's. IF I remove the inner select and replace with a list of comma seperated id's like this:
...where object_id in ( 123, 456, 8778, 999)
The overall query runs.
With the original code above, the query never returns and times out.
Question: Is anyone aware of something on FB side that broke around the middle of October in this regards? Or is there something inherently wrong with doing a subquery like this?
Any suggestions on how to work around?

Net: query returned TOO much data. If you have this problem, break up the result set somehow so it returns a smaller set of data. Would be nice if API returned some discernable status telling you so but....

Related

Get entire record with max field for each group

There are a lot of answers about this problem, but none of them retrieves the entire record, but only the ID... and I need the whole record.
So, I have a table status_changes that is composed of 4 columns:
issue_id : the issue the change refers to
id: the id of the change, just a SERIAL
status_from and status_to that are infact the status that the issue had before, and the status that the issue got then
when that is a timestamp of when this happened
Nothing too crazy, but now, I would like to have the "most recent status_change" for each issue.
I tried something like:
select id
from change
group by issue_id
having when = max(when)
But this has obviously 2 big problems:
select contains fields that are not in the group by
2 having can't contains aggregate function in this way
I thought of "ordering every group by when and using something like top(1), but I can't figure out how to do it...
Use PostgreSQL's DISTINCT ON:
SELECT DISTINCT ON (issue_id)
id, issue_id, status_from, statue_to, when
FROM change
ORDER BY issue_id, when DESC;
This will return the first result (the one with the greatest when) for each issue.

FQL: Get comment data WHERE object_id={a known object_id} works, but WHERE id={a known comment XID} does not?

I'm using FQL to get comment data from webpage with a Facebook comment box. I use the graph to get the object_id, then use FQL to get all comments with that object_id. However, if I want to pull data from a specific comment using its id (sometimes referred to as an XID) the FQL returns 0 results.
According to https://developers.facebook.com/docs/reference/fql/comment/ the id should be indexed, so this query should work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id={some known XID}
But it doesn't. BTW, THIS query does work:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+object_id={some known object_id}
It is irritating how I can't pull query for comments using time or fromid or anything other than object_id, id, post_id, and parent_id... but in practice only using the object_id returns anything.
has anyone else run into this problem? Is my XID query wrong somehow, or is the id only indexed on certain kinds of comments, and not webpage comments for no inexplicable reason?
This one I managed to solve with trial and error. I had to put the id in single quotes. It's odd, I could query the object_id without putting it in quotes, but not the id. This is sort of what the working FQL looked like, except with a valid access token:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id='#########_####'
as opposed to:
SELECT+id,+text,+time,+fromid,+is_private+FROM+comment+WHERE+id=#########_####
which failed to return any results.
Thanks for being consistent, Facebook :(

FQL like operator

Can someone tell me why this works:
SELECT name FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1=me()) AND strpos(lower(name),"jo") >=0
however this does not:
"SELECT url, id, type, site FROM object_url WHERE strpos(lower(url), 'sephora') >= 0"
When I put it in http://developers.facebook.com/docs/reference/rest/fql.query/
I get this response:
Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http://developers.facebook.com/docs/reference/fql
however "url" in indeed indexable.
any thoughts? I've already scoured stackoverflow but no answers found.
Site isn't indexable, it's only selectable. It doesn't have an * next to it here https://developers.facebook.com/docs/reference/fql/object_url/
you need to use url or id as the indexable column, so basically one of those needs to be in your where clause.
FQL != SQL You can't a a WHERE on any column you want. Not surprising considering the performance required with so many concurrent writers, I mean, one person in every ten in the world has signed up.
The problem in the second example is that a field used as a parameter in one of the string functions loses its indexability. It has to be the column itself.

How could I use FQL to query all the events without using indexable column which is marked *

I have a problem to solve.
I want to query all the events and I want to find the specific string.
The FQL code is like the following:
SELECT eid, name, location, start_time, end_time FROM event WHERE strpos(lower(location),'test') >=0
When I used this FQL code,it always occurred error.
The error message is "Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http://developers.facebook.com/docs/reference/fql"
Please,give me your point of views~thank you :)
Well, the error message is clear:
Your statement is not indexable. The
WHERE clause must contain an
indexable column. Such columns are
marked with * in the tables linked
from
http://developers.facebook.com/docs/reference/fql
So simply your approach won't work.
EDIT:
To further explain why this is not possible:
Facebook deals with "over than 900 million objects that people interact with (pages, groups, events and community pages)". reference.
So basically giving you (all App devs) the ability to search ALL pages, events, groups...etc will definitely bring the system down. This is why these "indexible" fields are selected carefully.
For instance, if you want to search events by "location" then these events should be "somehow" related to your application. Like created by your App for example, and you should have their ids stored somewhere so that something like this would work:
SELECT eid, name, location, start_time, end_time FROM event WHERE
strpos(lower(location),'test') >=0 AND eid IN (ids_from_your_db)

Facebook - max number of parameters in “IN” clause?

In Facebook query language(FQL), you can specify an IN clause, like:
SELECT uid1, uid2 FROM friend WHERE uid1 IN (1000, 1001, 1002)
Does anyone know what's the maximum number of parameters you can pass into IN?
I think the maximum result set size is 5000
It may seem like an odd number (so perhaps I miss counted, but it's close ~1), but I can not seem to query more than 73 IN items. This is my query:
SELECT object_id, metric, value
FROM insights
WHERE object_id IN ( ~73 PAGE IDS HERE~ )
AND metric='page_fans'
AND end_time=end_time_date('2011-06-04')
AND period=period('lifetime')
This is using the JavaSCript FB.api() call.
Not sure if there is an undocumented limit or it might be an issue of facebook fql server timeout.
You should check if there is a error 500 returned from FB web server which might indicate you are passing a too long GET statement (see Facebook query language - long query)
I realized my get was too long so instead of putting many numbers in the IN statement, i put a sub-query there that fetches those numbers from FB FQL - but unfortunately it looks like FB couldn't handle the query and returned an 'unknown error' in the JSON which really doesn't help us understand the problem.
There shoud not be a maximum number of parameters as there isnt in SQL IN as far as I know.
http://www.sql-tutorial.net/SQL-IN.asp
just dont use more parameters than you have values for the function to check because you will not get any results (dont know if it will give away an error as I never tried to).