r/SQL • • Sep 13 '26

MySQL SQL should have coordinates by default

ynot? Why does SQL not have coordinates for it's tables?
like what if i want to see table 2 row 1 column 5 and have a command for just that.
No names required

0 Upvotes

12 comments sorted by

4

u/Eleventhousand Sep 13 '26

If you wish to implement your own matrix, I would suggest doing it in a row-based methodology. For example, a column for row_id, a column for column_id, and a column for value. That way, you could reference coordinates in the where clause.

1

u/Code_Ynot Sep 13 '26

What i'm proposing here is to eliminate the need to do it every time for every table.
what if there were already a column for row_id and a row for column_id by default, wouldn't that make it easy ? and SQL slighlty better?

3

u/Eleventhousand Sep 13 '26

There cannot already be a column for row_id. SQL is not deterministic on rows that way. You need to supply an order by to order the rows.

Column_id is slightly different, because there are ordinal positions of columns in tables. But would there be a point in shortcutting column to an integer when it doesn't make sense for row, thereby implementing a half-baked solution of your requirement? Would there be a point in shortcutting column to an integer when you could just name the column 1, 2, 3, etc.? Would there be a point in shorcutting column to an integer when it could introduce new types of ambiguity? Every time that you introduce a second table via a join, you'd be forced to fully qualify the column name. Would there be a point in "eliminate the need to do it every time for every table" as you put it, when it only takes a few seconds to model a table via my proposed solution to begin with?

Don't get me wrong, I understand what you're trying to achieve. As someone who has written SQL every day for the past twenty-five years, there has been been an instance every couple of years where a feature as you proposed might have saved me two or three minutes.

1

u/alinroc SQL Server DBA Sep 13 '26

wouldn't that make it easy

No, it would make it infinitely harder. Names give things meaning. Integers are...just integers. So you'd still have to look up those IDs every time you needed to write a query.

Why do you think this would make it easier?

14

u/alinroc SQL Server DBA Sep 13 '26

SQL doesn't have "coordinates" because tables are not spreadsheets (BTW, you can name columns in most spreadsheets and reference them that way). It's not even a matter of "have by default" vs. "as an option" because it doesn't even exist "as an option."

A table in a relational database has no defined order; in a result set, this is even more evident as the ordering of results is never guaranteed without an explicit ORDER BY clause. This renders your row "coordinate" invalid.

Column positioning can change (most DBAs cringe at reordering columns because it's incredibly expensive), rendering your column "coordinate" invalid.

There are some RDBMSs and situations where it is possible to refer to a column by its ordinal position, but it's not what you're asking for here.

Row and column numbers are purely a construct in client applications for visual reference. Nothing more.

6

u/r3pr0b8 GROUP_CONCAT is da bomb Sep 13 '26

why not?

because tables aren't numbered, so table 2 makes no sense

because rows aren't numbered, so row 1 makes no sense

because columns aren't numbered, so column 5 makes no sense

your idea? it doesn't make any sense

4

u/alinroc SQL Server DBA Sep 13 '26

because tables aren't numbered, so table 2 makes no sense

Waddaya mean? Everyone knows that F0002 is the Business Unit Master table and F0911 is the Account Ledger. Makes perfect sense to me!

I wish I was joking, but if you've used JDEdwards / OneWorld, you know the pain

4

u/ncmtbiker Sep 13 '26

A database table is not an Array. They are modeled after mathematical sets. So the rows have no guaranteed inherent order without an explicit ORDER BY clause.

The columns do have a defined position. This created when the table is designed. Which allows for order by 5, which will order by the 5th columns. This is VERY bad coding because a new column can be added anyplace in a table and would break your query.

4

u/feignapathy Sep 13 '26

There'd have to be some kind of ordering applied to the data. Otherwise, you're just pulling a random record or whatever. 

And what exactly does that achieve? 

2

u/alinroc SQL Server DBA Sep 13 '26

what exactly does that achieve?

Security by obscurity! Attackers can't get at our customers table if they don't know it's actually table 295.

2

u/RainbowFlesh Sep 13 '26

In what scenario would you ever want that?

1

u/TheLuminary Sep 13 '26

Why... Would you want that? What would you do if the column order changes. Or the table order changes?

Better to increase your specificity with table and column names. I don't see any reason why your idea of numeric access to database information would be preferable.

What would your use case be?