2

I'm working with my first CartoDB.js application.

I created a visualization on the app using

cartodb.createVis('map', visjson_url, opts);

The app has two layers, base map and data layer. the data layer has five sublayers. Each sublayer represents data in an independent table (i.e., sublayer1 represents table1, etc.).

I run queries using this statement:

data_layer.getSubLayer(sublayer_index).setSQL(query_str);

The problem is that I get an error message saying "Bad Request" if query_str involves join operations between some of the tables (e.g., spatial join between table1 and table3). If query_str is related to only one table (without joins), setSQL() above works fine.

How can I display join results using setSQL() that involves join operation between two or more sublayers?

  • Have you tried the same queries through the SQL tray in your CartoDB account? Could you share a sample query here? layer.setSQL(...) supports arbitrary queries against your database. – Andy Eschbacher Jan 21 '16 at 2:21
  • Andy, thank you for your attention. I ran $.getJSON('https://myaccount.cartodb.com/api/v2/sql/?q=SELECT * FROM table1 INNER JOIN field1 ON ST_Intersects(table1.the_geom, table2.the_geom) INNER JOIN table3 ON ST_Intersects(table2.the_geom, table3.the_geom)', function(data) { console.log(data); }); on the javascript console of the webbrowser. It doesn't give me the error. This is why I thought there's an error in visualizing part, rather than DB access. Any advice will be appreciated. – user65622 Jan 26 '16 at 23:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.