r/SQL • • 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

19 comments sorted by

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

3

u/throw_mob 1d ago

agree, db system mastery and using features can give cleaner code, faster execute etc. From my experience database systems change needs extensive refactoring and testing anyway that there is no reason miss beneficial features on one used.

2

u/KeyPreparation1320 1d ago

I agree, on top of it often times you end up fighting the mechanism instead of just putting it in a line or two.

Specifically with transactions, job executions, parallelism and sometimes with small things such as Date and time.

2

u/throw_mob 1d ago

fully agree, time handling tends to db specific. for example m i used tiemstamp_ltc in snowflake as default timestamp and handled data insertion to be systematic. Then session specific timezone handled all reporting for localtime. That kind of style is database specific ( which can be ported to postgresql but mssql might give headaches )

2

u/KeyPreparation1320 1d ago

Similar problem happened with me in hive, while partitioning based on some dates. Ig its universal

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/instructiveslugger5 1d ago

If you write it, you maintain it, so lean into whatever makes your life easier now.

2

u/ComicOzzy sqlHippo 1d 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 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.

2

u/Mathie1729 1d 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 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.