News for hackers. Stuff that matters.
Re:PRQL – A proposal for a better SQL by inglor on Monday January 24, 2022 @03:41PM (#30063711)
The big advantage of "from first" like we have in Kusto KQL (a database we use at Microsoft) is that it provides much better autocomplete (if I write the `from` it can easily autocomplete the projection).

If you want an interesting example of how a query language built for developer experience and autocompletions looks definitely check it out!.

Re:PRQL – A proposal for a better SQL by lemmsjid on Monday January 24, 2022 @03:49PM (#30063829)
That's interesting because it also explains why I was going to say I do like having from first. When trying to reason about a query, I mentally go through the following:

1. What tables are being pulled from? This speaks to the potential domain of the query. 2. What data is being selected (I can now know what is or isn't being pulled from the aforementioned tables...) 3. What operations, aggregations, groupings, etc. are being performed to work on the pulle data

Of course from vs select ordering is completely arguable, but my thinking process seems to follow that of the auto complete--in other words that my cognitive load of looking at the select statement is lessened when I know from what the columns are being selected.

It also follows (at least to me) the mental process of writing the query. First look at the tables, then decide what columns, then decide what functions to apply.

Re:PRQL – A proposal for a better SQL by taeric on Monday January 24, 2022 @04:11PM (#30064094)
I said it in a sibling, but I feel this is somewhat missed. Auto complete that simply lists the tables is easier if from is first. But... Auto complete that helps me know what tables can give me my requested columns works the other direction.
Re:PRQL – A proposal for a better SQL by majkinetor on Monday January 24, 2022 @04:43PM (#30064461)
Too bad we can't use Kusto with anything except Azure.
Re:PRQL – A proposal for a better SQL by _jal on Monday January 24, 2022 @03:46PM (#30063795)
Designing languages around autocomplete is like designing toilets for better toilet paper dispensers.

The language should be right for human understanding, not automated mad-lib generation.

Re:PRQL – A proposal for a better SQL by inglor on Monday January 24, 2022 @03:54PM (#30063895)
You would think that but having used both I find writing Kusto/KQL much smoother, neater and faster and if I have to choose between writing a query in either one I'd pick KQL.

I understand this is just an opinion but it's an opinion held by everyone in my org who writes both.

Theoretical correctness loses to pragmatism a lot and I'd read the KQL every day. Look at the examples at https://docs.microsoft.com/en-us/azure/data-explorer/kusto/q... - look at the examples at https://docs.microsoft.com/en-us/azure/data-explorer/write-q... and tell me they're not more readable than comparable SQL?

(I can see the result type both by hovering on the query but also by just looking at the end of it - and in SQL most of the SELECTed items in complex queries are from subqueries anyway - at least in my use case)

Re:PRQL – A proposal for a better SQL by keithnz on Monday January 24, 2022 @04:41PM (#30064437)
now if MS made a KQL -> TSQL or support it natively in SQL Server, that would be great :)
Re:PRQL – A proposal for a better SQL by adamrezich on Monday January 24, 2022 @04:52PM (#30064582)
yes please!!
Re:PRQL – A proposal for a better SQL by phailhaus on Monday January 24, 2022 @03:54PM (#30063893)
Building for autocomplete is building for human understanding. If it is impossible for a computer to determine the context of your query, why would a human do much better?
Re:PRQL – A proposal for a better SQL by _jal on Monday January 24, 2022 @04:14PM (#30064140)
They are not fully-aligned goals, and autocomplete should not be given equal consideration on par with human clarity.

If you want nice autocomplete too, that's fine, but if there is a tradeoff, human understanding is the primary concern.

Re:PRQL – A proposal for a better SQL by tester756 on Monday January 24, 2022 @04:24PM (#30064248)
I don't understand why do you think about it this way

C#'s LINQ (really powerful tool similar to SQL) works the same way

look:

var list = new List<int>{1,2,3}

var extracted = list

.............................Where(x => x > 1)

.............................Select(x => $"my number: {x})

.............................ToList();

or

var extarcted =

........................from x in list

........................where x > 1

........................select $"my number: {x};

Re:PRQL – A proposal for a better SQL by ziml77 on Monday January 24, 2022 @10:50PM (#30067735)
Technically to be equivalent you need to wrap the second one in parentheses so you can use ToList() on it. Unfortunately a bit ugly. I'm not sure why they didn't add one more keyword to handle pipelining into other functions. Something like "feed", "into", or "pipe". Or just pluck the |> operator from F#.
Re:PRQL – A proposal for a better SQL by jiggawatts on Monday January 24, 2022 @04:03PM (#30063998)
I’ve been frustrated by toilets where I have to contort my body to reach the dispenser. Similarly, I’ve had dispensers intrude on the space where my legs would normally be and make it awkward to even just sit on the toilet.

Toilets are absolutely designed to make the dispenser placement convenient. You just don’t think about it because 95% of toilets get it right, so it just doesn’t bother you that much that it can be wrong.

In SQL, some decisions are right about 10% of the time and are annoying and awkward the other 90%.

That’s why the order matters. Because everything else got it right.

Re:PRQL – A proposal for a better SQL by oldsecondhand on Monday January 24, 2022 @04:04PM (#30064009)
There's a person behind the IDE. If you help the IDE, you help the person using the IDE.
Re:PRQL – A proposal for a better SQL by emteycz on Monday January 24, 2022 @03:52PM (#30063863)
I'd agree if there was any way whatsoever of fixing this issue, but there simply isn't. The editor can't even begin to guess what you might want until you write your FROM.
Re:PRQL – A proposal for a better SQL by taeric on Monday January 24, 2022 @04:14PM (#30064134)
Maybe in gigantic systems with more tables than makes sense. Realistically, all of the columns available in a database can be fit in memory with ease.

Then, the ide could basically fill my from out for me, based on what I'm asking for. Can even suggest what join I will need, if I list columns from multiple tables.

Re:PRQL – A proposal for a better SQL by tester756 on Monday January 24, 2022 @04:29PM (#30064311)
>Maybe in gigantic systems with more tables than makes sense. Realistically, all of the columns available in a database can be fit in memory with ease.

Every table has more than one column

So there's always more columns to remember than tables and generally tables are pretty easy like user invoices blabla

I worked with systems that had like 500 tables and some of them with 20-50 columns

you really want good intellisense in such a environment

Re:PRQL – A proposal for a better SQL by taeric on Monday January 24, 2022 @04:36PM (#30064392)
500 times 50 is still not a big number. And you could do decent statistical suggestions on the current columns in.

Good intelligent suggestions is, of course, helpful. And I agree that suggesting one of 500 is easier than the other. That said, neither is hard for a computer. And even asking friends what table I want will often be done with starting with the actual columns I want.

Re:PRQL – A proposal for a better SQL by tester756 on Monday January 24, 2022 @04:38PM (#30064411)
On the other hand I don't see why it couldnt work both ways

if you start query with

SELECT MiddleName then you could receive auto complete thats adds "FROM Users" and moves your cusor after MiddleName.

if you start query with

FROM Users SELECT _ and know intellisense drops list of columns

Re:PRQL – A proposal for a better SQL by taeric on Monday January 24, 2022 @04:48PM (#30064531)
Agreed. I'm really just arguing that it doesn't have to be from first.
Re:PRQL – A proposal for a better SQL by Xelbair on Monday January 24, 2022 @03:53PM (#30063875)
And one of use cases is writing queries which it helps immensely. Best of both worlds would allow both orders. Just automatically transform the query to the usual form after it's execution.