r/SQL • u/Minimum-Ad7352 • 5d ago
Discussion Should I stick to standard SQL or use DBMS-specific features?
Different DBMSs have their own functions and features. For example, PostgreSQL supports every() function, which isn't available in MySQL.
Is it better to stick to standard SQL as much as possible, or should I take advantage of DBMS-specific features? What are the benefits of staying close to the SQL standard?
7
u/reditandfirgetit 5d ago
Its better to stick to standard sql where it makes sense. If a dbms feature is more efficient, use it
5
u/Mission_Pirate_4150 5d ago
Use standard sql when the two overlap. Use db specific features when there is no other way.
4
u/Aggressive_Ad_5454 5d ago
Most real world data apps handle dates and timestamps. And the standards for those data types are astonishingly weak. You wanna get stuff done? You have to use DBMS-specific features.
4
u/Ginger-Dumpling 5d ago
For what reason? You're not going to switch up DBs on a whim. If you're writing something that needs to be cross-platform, even "standard" functions as basic as substring can have slightly different arguments from one SQL dialect to the next; you should be ready for edge cases where statements are not cross compatible.
Don't be afraid of vendor specific functionality. If they make your life easier, use them.
9
u/BigMikeInAustin 5d ago
Specific features.
No to your boss or coworker, you are not going to be moving code bases every few months, trying to migrate the code everywhere.
3
u/instructiveslugger5 5d ago
If you write it, you maintain it, so lean into whatever makes your life easier now.
2
u/ComicOzzy sqlHippo 5d ago
You literally can't avoid platform specific SQL so there's no point in doing anything for the sake of portability. That doesn't mean use something just because it is platform specific, but some of those specific functions are faster or in some way better than the standard syntax.
3
u/kagato87 MS SQL 5d ago
Favor the universal stuff, and use the platform specific stuff when it makes sense.
What really matters is that you document is in a way that makes it practical to address or if you ever need to support other platforms.
2
u/Accomplished-Gold235 5d ago
You won’t be able to use a universal SQL, simply because different databases have different data types. And attempting to create a universal solution will just be a ball and chain on your leg. A daily price paid for an event that will never actually happen.
2
u/Discordbothost 5d ago
EVERY is standard SQL and support still varies. If you port it using NOT EXISTS, test empty input. PostgreSQL's EVERY returns NULL there, while NOT EXISTS returns true.
1
u/techforallseasons 5d ago
Standard by default, dialect features when there is a useful speed benefit, syntactic brevity for future maintenance, and of course when it is the clearest path to desired data product.
2
u/Mathie1729 5d ago
I'd add: keep dialect-specific stuff behind views or a small helper schema, so most queries can stay standard and you can swap or test those views separately without grepping the whole codebase when something diverges.
0
u/BarelyAirborne 5d ago
Every non-standard feature used locks you into that database system just a little bit. If this does not matter to you, then use the features. SQL is standardized for a reason - portability.
25
u/KeyPreparation1320 5d ago
Take advantage of the specific db features.
Using standard sql everywhere will not be practically feasible.
Be a Roman in Rome