Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How necessary or convenient is it to write portable SQL?

Time and again, I've seen people here and everywhere else advocating avoidance of nonportable extensions to the SQL language, this being the latest example. I recall only one article stating what I'm about to say, and I don't have that link anymore.

Have you actually benefited from writing portable SQL and dismissing your dialect's proprietary tools/syntax?

I've never seen a case of someone taking pains to build a complex application on mysql and then saying You know what would be just peachy? Let's switch to (PostGreSQL|Oracle|SQL Server)!

Common libraries in -say- PHP do abstract the intricacies of SQL, but at what cost? You end up unable to use efficient constructs and functions, for a presumed glimmer of portability you most likely will never use. This sounds like textbook YAGNI to me.

EDIT: Maybe the example I mentioned is too snarky, but I think the point remains: if you are planning a move from one DBMS to another, you are likely redesigning the app anyway, or you wouldn't be doing it at all.

like image 765
Adriano Varoli Piazza Avatar asked Sep 15 '09 12:09

Adriano Varoli Piazza


People also ask

Why is SQL necessary?

What is SQL used for? It's used to interact with relational databases. A regional database organizes data into tables, like an excel spreadsheet. SQL works by understanding and analyzing data of virtually any size, from small datasets to large stacks.

What is SQL write down the advantages of SQL?

Structural Query Language (SQL) is used for accessing, manipulating, and communicating with the database. Almost every function such as retrieving data from the database, creating a new database, manipulating data and databases such as insertion, deletion and updation can be performed using SQL.

How is SQL used in the real world?

SQL is widely used in business and in other types of database administration. It is often the default tool for “operating” on the conventional database, to alter tabled data, retrieve data or otherwise manipulate an existing data set.


2 Answers

Software vendors who deal with large enterprises may have no choice (indeed that's my world) - their customers may have policies of using only one database vendor's products. To miss out on major customers is commercially difficult.

When you work within an enterprise you may be able to benefit from the knowledge of the platform.

Generally speaking the DB layer should be well encapsulated, so even if you had to port to a new database the change should not be pervasive. I think it's reasonable to take a YAGNI approach to porting unless you have a specific requriement for immediate multi-vendor support. Make it work with your current target database, but structure the code carefully to enable future portability.

like image 92
djna Avatar answered Sep 24 '22 13:09

djna


The problem with extensions is that you need to update them when you're updating the database system itself. Developers often think their code will last forever but most code will need to be rewritten within 5 to 10 years. Databases tend to survive longer than most applications since administrators are smart enough to not fix things that aren't broken so they often don't upgrade their systems with every new version.
Still, it's a real pain when you upgrade your database to a newer version yet the extensions aren't compatible with that one and thus won't work. It makes the upgrade much more complex and demands more code to be rewritten.
When you pick a database system, you're often stuck with that decision for years.
When you pick a database and a few extensions, you're stuck with that decision for much, much longer!

like image 23
Wim ten Brink Avatar answered Sep 25 '22 13:09

Wim ten Brink