Live data from Hacker News

It's not you, it's SQL

stack.convex.dev

61–70 of 84 posts

Re: It's not you, it's SQL

#61

My biggest issue with sql has and always will be the lack of definitions. There's no way to express data structure knowledge in sql, only relations and keys. Discoverability can be quite lacking. And every time I want to join table A to B I have to re-define everything, because SQL doesn't store that. ORMs help. They help because they encode relationships in meaningful ways. A has many Bs, so A.B works, and I don't n…

> There’s no way to express data structure knowledge in sql, only relations and keys.

Relations, keys, and (though you forgot them) constraints express…quite a lot of data structure knowledge.

> And every time I want to join table A to B I have to re-define everything, because SQL doesn’t store that.

SQL stores that if you tell it to; the usual way being view CREATE VIEW.

Re: It's not you, it's SQL

#62
post #14

Earlier quoted context omitted.

Article author, here. Good point -- but the article actually proposes document relational, not hierarchical. Relational is definitely good!

It vaguely references it, doesn’t explain what the data model it is proposing actually is in concrete terms. It gives some API examples, but nothing that tells me what is different between it and the data model of any of the major (Object) Relational DBMS’s with an appropriate host-language client adaptor except that the client library exists only for TS and the type system is designed to be 1:1 with TypeScript. And…

> doesn’t explain what the data model it is proposing actually is in concrete terms.

Fair enough. The goal of the post wasn't necessarily to comprehensively describe the product–so the specifics of what we provide are found elsewhere in our docs, etc.

> Really, the big thing that I see here is the transaction retry logic,

These transactions run as embedded functions inside Convex in a runtime where it is impossible to have side effects.

Re: It's not you, it's SQL

#63
post #46

Earlier quoted context omitted.

A database system could implement a feature that automatically uses the foreign key to join to a table. Maybe some RDBMS out there does this. For example, you have a many to one relationship between posts and users. Instead of this: select * from user as u join post as p on p.user_id = u.user_id; You could do: alter table post add constraint fk_user_id foreign key (user_id) references user.user_id; select * from user…

SQL already covers this use case with the `using` keyword. But you need to specify the shared column name. If you didn't need to specify the column then adding a new foreign key between the tables would make existing queries ambiguous and break backwards compatibility. See: https://www.postgresql.org/docs/current/queries-table-expres... .

> SQL already covers this use case with the `using` keyword.

No, “using” doesn’t automatically join by foreign key, it joins by explicitly-provided column name which must be identical between the two tables.

> If you didn’t need to specify the column then adding a new foreign key between the tables would make existing queries ambiguous and break backwards compatibility.

Not if you specified with constraint name rather than the column name (which also works for multi-column foreign keys without having to reiterate all the columns, being much more DRY than current SQL USING.)

Better, with that approach you could also allow fully implicit joins, using the foreign key constraint name as if it were an row-valued field in the referencing table.

E.g.:

  CREATE TABLE employees (
    id BIGSERIAL PRIMARY KEY,’
    name VARCHAR,
    manager_id BIGINT CONSTRAINT manager REFERENCES employees
  );
would let you do:

  SELECT name as employee_name, manager.name as manager_name
  FROM employees
as syntax sugar for:

  SELECT ee.name as employee_name, mgr.name as manager_name
  FROM employees ee 
  LEFT JOIN employees mgr ON (
    employees.manager_id = mgr.id
  )

Re: It's not you, it's SQL

#64
post #59

Earlier quoted context omitted.

But a view also does that? Like, if you want to assemble information about a user from several different tables, you can have a view that does the join for you.

Sure, but people never use those. Also it gets back to the discoverability issue. The ORM documents relationships with the rest of the model code, if you have a poorly named view in a large, complex schema it may be hard to find. You could reinvent the wheel easily. Like everything with SQL, you can solve the problem but sometimes the solution isn't elegant. People want elegance.

This is an accurate description of how I think of this problem. And it would be tough to describe all this:

- table a joins b yay a view

- table b joins c yay a view

- table c join d yay a view

- table a joins to d. well technically it can, but are you really gonna write all the permutations of views for every possible join?

ORMs encode that nicely so I can easily walk the relationships and get to the query I need.

Re: It's not you, it's SQL

#65
post #54
post #51

I agree with lots of the points here. However one of the great strengths of the SQL family is the FOSS history. I doubt something proprietary is ever going win everyone over. At least I hope not.

Article author here. Agree this is a necessary part of the change. Convex is working on our OSS strategy this year. Thanks for the feedback!

Awesome! This is a great article. I've been thinking lately about how ORMs are basically a band-aid meant to fix the weaknesses of SQL, so it's great to see people trying to solve the problem from the bottom up.

Re: It's not you, it's SQL

#66

On the other side of things, it's interesting to see SQL engines innovating. Though the only one I can name for sure is DuckDB: https://duckdb.org/2022/05/04/friendlier-sql.html . Have other implementations done anything for making queries easier (that don't involve requiring an IDE or anything, so just query language innovations)? Edit: Not query language innovations but ClickHouse and Snowflake's "standard library"…

+1 to ClickHouse builtin functions—they vastly simplify a lot of data analytics workloads

Re: It's not you, it's SQL

#67
post #62

Earlier quoted context omitted.

It vaguely references it, doesn’t explain what the data model it is proposing actually is in concrete terms. It gives some API examples, but nothing that tells me what is different between it and the data model of any of the major (Object) Relational DBMS’s with an appropriate host-language client adaptor except that the client library exists only for TS and the type system is designed to be 1:1 with TypeScript. And…

> doesn’t explain what the data model it is proposing actually is in concrete terms. Fair enough. The goal of the post wasn't necessarily to comprehensively describe the product–so the specifics of what we provide are found elsewhere in our docs, etc. > Really, the big thing that I see here is the transaction retry logic, These transactions run as embedded functions inside Convex in a runtime where it is impossible t…

> These transactions run as embedded functions inside Convex in a runtime where it is impossible to have side effects.

The reason I expressed that the side effect free version would be useful in any engine, and the side effect encompassing one would be useful in any client library, is transaction patterns where external interaction is needed within the transaction are not uncommon. A tradeoff of automatic transaction retries for a constraint that you can never have client-side side effects conducted between operations of a database transactions means you are likely to have to write more higher level business transaction compensation logic around lower-level database transactions. This may, in one respect, have greater conceptual purity, but in practical terms its a trade off, not a pure gain.

Re: It's not you, it's SQL

#68

The article presents the move from the old, doddering SQL to the newer, better NoSQL - but the hierarchical database model actually _predate_ SQL. The first databases like IBM's IMS were hierarchical a lot like Mongo is: Codd was actually trying to address the problems with that model when he created the relational model.

Comparing any modern database (i.e. developed after 1980) with IMS is like comparing a flint knife with a Barrett .50 calibre.

Which one is the flint knife and which one is the Barrett .50 calibre?

Re: It's not you, it's SQL

#69
post #59

Earlier quoted context omitted.

Sure, but people never use those. Also it gets back to the discoverability issue. The ORM documents relationships with the rest of the model code, if you have a poorly named view in a large, complex schema it may be hard to find. You could reinvent the wheel easily. Like everything with SQL, you can solve the problem but sometimes the solution isn't elegant. People want elegance.

This is an accurate description of how I think of this problem. And it would be tough to describe all this: - table a joins b yay a view - table b joins c yay a view - table c join d yay a view - table a joins to d. well technically it can, but are you really gonna write all the permutations of views for every possible join? ORMs encode that nicely so I can easily walk the relationships and get to the query I need.

Essentially all of the actual information is encoded in the foreign key constraints (in combination with uniqueness constraints.) What ORMs provide that SQL doesn’t isn’t much encoding of information (they usually have facilities to distinguish data tables from pure join tables, and to distinguish 1:1 and 1:M, (M>0) relations from 1:(0-1) and 1:M, (M>=0) ones, so they do encode some additional information), but provide convenient syntactic shorthands for the client to use the encoded relationships.

This would be easy to add to SQL, as syntax sugar, https://news.ycombinator.com/item?id=34587412

Re: It's not you, it's SQL

#70
post #2

> Tab! Tab! Tab! PostgreSQL demonstrates its field autocomplete feature. SELECT preceeding FROM is such a thorn in the side. :(

I wish SQL did not require a comma between items after the SELECT and before the FROM. We don't need commas in between joins. I feel like someone could write a way to parse queries so that it isn't needed. Can you imagine how much time and effort that would save people? Edit: You do need commas in ORDER BYs, that slipped my mind when typing out this pet peeve of mine.

> I wish SQL did not require a comma between items after the SELECT and before the FROM.

> Can you imagine how much time and effort that would save people?

I can imagine how much extra time I’d spend typing “AS” in queries, which would ne necessary for column aliases to be distinct from new select items. And how much more time I’d spend reading unreadable queries in contexts like logs where they aren’t pretty-printed. Net, it seems to be a big loss.

> We don’t need commas in between joins.

That’s because each join is introduced by a string of one or more reserved words (including JOIN).

If each select field was prefaces with FIELD you wouldn’t need commas, but...

Post reply on HN