News for hackers. Stuff that matters.
Re:Our SQL interview questions by acjohnson55 on Tuesday May 28, 2013 @08:54AM (#5779643)
I could nail those with the Django ORM, but I'd struggle to write syntactically correct SQL, not having done it in a while. But it says that your test machine has MS-SQL; with the machine in front of me, I could probably puzzle it out the join quirks with a couple minutes of trial and error.
Re:Our SQL interview questions by Tyrannosaurs on Tuesday May 28, 2013 @09:05AM (#5779705)
I think if you don't give someone a machine you should be pretty forgiving about exact syntax.

Someone who can put together a statement that's broadly right with small errors normally means someone who is rusty (or nervous) but knows their stuff rather than someone who is guessing and a couple of follow up questions will usually confirm that.

General rule for me: don't ask anything that a decent IDE or 10 seconds with a manual / help file / Google would have prevented (unless you've given them a decent ID or similar in which case it's fair game).

Re:Our SQL interview questions by jfb on Tuesday May 28, 2013 @09:12AM (#5779744)
So the question is, do you represent yourself as a SQL developer? If not, no drama.
Re:Our SQL interview questions by tomp on Tuesday May 28, 2013 @08:55AM (#5779651)
How would you solve the first one using Django ORM?
Re:Our SQL interview questions by dalore on Tuesday May 28, 2013 @09:10AM (#5779738)
Employee.objects.filter(boss__salary__lte=F('salary'))

Find me employee objects which have a boss salary less than or equal to the salary.

Re:Our SQL interview questions by PeterisP on Tuesday May 28, 2013 @09:39AM (#5779933)
Out of curiosity, would the ORM map to the same SQL query? Or would it request all employee-boss pairs and filter them outside of the DB?

There's a huge performance difference involved.

Re:Our SQL interview questions by freework on Tuesday May 28, 2013 @04:51PM (#5782692)
Potentially huge performance difference.

For the 99% use case, the performance hit fo the ORM is not significant enough to matter. Most projects have many tables, but only one table that actually needs to have any speed optimizations. That one table can go in NoSQL and the rest can be handled by a ORM.

Re:Our SQL interview questions by metaphorm on Tuesday May 28, 2013 @01:33PM (#5781316)
this is a good question. my experience with the django ORM is that in general it resolves any call to an ORM method into SQL and nothing else, but it is not guaranteed to generate the most optimal SQL.

It is however, a somewhat common practice of django devs to to do some post-processing on a queryset in Python. totally acceptable for small querysets with complicated logic, but, yeah, obviously unacceptable for large performance critical queries.

Re:Our SQL interview questions by dalore on Thursday May 30, 2013 @01:02PM (#5793678)
It will only be one query. The django orm won't do any filtering outside the DB that is up to you.
Re:Our SQL interview questions by damon_c on Tuesday May 28, 2013 @10:02AM (#5780075)
I believe Django would do this as a single query.
Re:Our SQL interview questions by jschmitz28 on Tuesday May 28, 2013 @01:30PM (#5781294)
It does not apply to the first question, but how does the ORM handle joined columns from other tables? Is it embedded somewhere in the returned object? The best way I could think to handle this using an ORM would be for the object to contain a set of arbitrary key/value pairs to contain joined columns but it seems like a hack.
Re:Our SQL interview questions by megaman821 on Tuesday May 28, 2013 @06:16PM (#5783225)
It is fetched dynamically e.g. employee.boss.department. That will usually cause two more queries to the database. You can use select_related and prefetch_related so that these objects will be loaded into the ORM in one or two queries.
Re:Our SQL interview questions by danielsamuels on Tuesday May 28, 2013 @09:29AM (#5779864)

  from .models import Employee
  from django.db.models import F

  print Employee.objects.filter(
      salary__gt=F('boss__salary')
  )
Re:Our SQL interview questions by megaman821 on Tuesday May 28, 2013 @09:10AM (#5779737)

    Employee.objects.filter(boss__salary__lte=F('salary')).values_list('names', flat=True)