Q: How to remove the limit of 1000 records per request - socrata

I am running this endpoint https://www.datos.gov.co/resource/qx3q-zr7u.json?limit=1000
I put a limit of a thousand records but I receive the following message
Unrecognized arguments [limit]

You need to add the $ symbol before the query keyword. This query will work:
https://www.datos.gov.co/resource/qx3q-zr7u.json?$limit=1000

Related

getting id from url inside sql query [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
I have an sql query to fetch data from database in php. I am using the limit to limit data. I need to limit data according to the id in the url.
How can I call the id in the sql query. I have tried the following but it's showing an error:
$response=mysqli_query($con,"select * from prometric ORDER BY RAND() LIMIT echo $_GET['id']; ");
and the error is
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting '-' or identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\nurse\prometricajax.php on line 14
It could be, worse, if you got it 'right' there would be an SQL injection vulnerability in your application.
die('the following appears to work but is unsafe');
$response=mysqli_query($con,"select * from prometric ORDER BY RAND() LIMIT $_GET[id]; ");
I've got die above because noone should use such code ever.
eg: called as
https://you.example.com/thing.php?id=1%3btruncate+prometric%3bcommit
could delete all the content from the prometric table.
At a bare minimum do this.
$response=mysqli_query($con,"select * from prometric ORDER BY RAND() LIMIT ".(0+$_GET['id']));
the above forces $_GET['id'] to a number by adding 0, this should block all injection attacks, the worst they can do is use a big number and produce an error for number too big, etc.
but probably a better sanitization is called for. Eg: copy $_GET['id'] into a variable, and check that is in an acceptable range before using it in SQL.
What you have is very very close. The extra echo in there along with the ; are what is causing you a problem. Try
$response=mysqli_query($con,"select * from prometric ORDER BY RAND() LIMIT " . $_GET['id']);

PG::InvalidColumnReference: ERROR when sorting by associated table

I'm trying to sort/order a table (Employer) based on the number of associated records (Employee) each (Employer) has.
The following code works on rails console with the Employer records sorted by number of Employees as intended :
Employer.joins(:employees).group(:id).order('count(employees.id) ASC')
However, when actually trying to run this on development, I get this error:
PG::InvalidColumnReference: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list
While I could use 'sort_by", I would prefer to have the result in ActiveRecord::Relation format. Any help would be appreciated.
I was able to reproduce this error in the console by adding distinct to the expression:
In your case it would be:
Employer.distinct.joins(:employees).group(:id).order('count(employees.id) ASC')
The error message says that you have to add the expression you sort by (count(employees.id)) to the select list.
That could be achieved by explicitly specifying select columns:
Employer.select('employers.id, count(employees.id)').joins(:employees).group(:id).order('count(employees.id) ASC')

nypd motor vehicle collisions api query

I am trying to query the nypd collisions API.
The following url is a successful query
"https://data.cityofnewyork.us/resource/qiz3-axqb.geojson?$where=within_circle(location,%2040.73214,%20-73.99860000000001,%20100)&number_of_persons_injured=1"
But i cannot seem to query the same with 'number_of_persons_injured > 0'
I get an error for that query when trying to combine it with 'within_circle'
It would be extra help if you could tell me how to query 'within_circle()AND(number_of_persons_injured > 0ORnumber_of_persons_killed > 0)'
Thank you
Is this more what you're thinking?
GET https://data.cityofnewyork.us/resource/qiz3-axqb.geojson?$where=within_circle(location,%2040.73214,%20-73.99860000000001,%20100)%20AND%20(number_of_persons_injured%20%3E%200%20OR%20number_of_persons_killed%20%3E%200)
All I did was drop the number_of_persons_injured=1 since that's duplicated in the $where, and I added spaces around your ANDs and OR.

Rails how to check what an sql query is producing

This query doesn't produce an error but I'm pretty sure EXTRACT(EPOCH FROM relationships.created_at) isn't doing what it's meant to.
last_check = #user.last_check.to_i
#new_relationships = User.select('"rels_unordered".*')
.from("(#{#rels_unordered.to_sql}) AS rels_unordered")
.joins("
INNER JOIN relationships
ON rels_unordered.id = relationships.character_id
WHERE EXTRACT(EPOCH FROM relationships.created_at) > #{last_check}
GROUP BY relationships.created_at
ORDER BY relationships.created_at DESC
")
How do I check exactly what EXTRACT(EPOCH FROM relationships.created_at) is producing? The server logs don't show it, they just repeat the query. (At least the logs do show that #{last_check} correctly produces a number like 1471364015, which is why I think the problem is with the epoch code.)
I would just go to mysql and try it out:
SELECT EXTRACT(EPOCH FROM relationships.created_at) FROM relationships limit 0,1;
and see what kind of answer you get. Alter the above to specify a particular record if need be.
A larger problem may be the EPOCH parameter; I'm not sure it's valid. See the mySQL reference for EXTRACT and its parameters.

Streaming Analytics Query Error

When typing my query for Streaming Analytics I don't receive any error messages, however, when I start my streaming analytics job, I receive the following error:
Stream Analytics job has validation errors: The output dsleads used in the query was not defined. Activity Id: '5cc961c5-4dbd-4a63-95df-8e3b08d2121c-2016-03-28 14:56:21Z'.
I've checked the output name and have verified that it's correct. I'm not sure what I'm doing wrong. The query I'm using is as follows:
SELECT type, count(*) as count, system.timestamp as time
INTO dsleads
FROM ttvhuball timestamp by time
GROUP BY type, TumblingWindow(minute, 10)
I've scoured the internet and have not found anything helpful.
seems like an output alias error. Is the output sink alias that you've created(that is you give a name to it during creation) "dsleads" in your case?
Also worth mentioning INTO is the output and FROM is the input. INTO always needs to come before FROM in the query as well.
Hope this helps!
Mert
I was using the incorrect output name. One needs to specify the output name. I was specifying the dataset name of the output I needed to specify.