r/SQL • u/Minimum-Ad7352 • 1d 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
Upvotes
20
u/KeyPreparation1320 1d ago
Take advantage of the specific db features.
Using standard sql everywhere will not be practically feasible.
Be a Roman in Rome
7
u/reditandfirgetit 1d 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 1d ago
Use standard sql when the two overlap. Use db specific features when there is no other way.
4
u/Aggressive_Ad_5454 1d 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 1d 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 1d 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/kagato87 MS SQL 1d 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 1d 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 1d 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 1d 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.
0
u/BarelyAirborne 1d 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.