3 ms·
This is honestly more of a feature that exists because the SQL standard specifies it, and supporting it can be useful for people porting code from another DB th
by jsmith45 3y ago
This is honestly more of a feature that exists because the SQL standard specifies it, and supporting it can be useful for people porting code from another DB that uses a similar system. If you are not doing that, then it doesn't seem to provide enough value to be worth the headache of ading an additional preprocessor to your build chain. Not to mention, it likely messes with syntax highlighting, linters, etc.
Indeed, this (or the equivalent in other languages) is one of the main ways the SQL standard expects to be used! It get presented before more familiar approaches, and various wording and placement choices make it clear that the standard considers this embedded SQL approach more core to how it works than other approaches.
A design like libpq, ODBC, etc where the sql syntax needs to be parsed at runtime rather than compile time is considered "dynamic sql" by the standard, and the standard acts like it is less likely to be provided than this interface. Obviously that is hogwash.
This is one of many reasons (like backwards compatibility) that unlike most other programming languages very few SQL implementations make much effort towards faithfully implementing the standard. PostgreSQL actually puts a lot more effort towards implementing the standard than many other popular RDBMses. Postgres has fairly few places where they intentionally violate the standard and don't hope to fix things in the future, and several are fairly obscure, or othewise not likely to cause issues. While Oracle has MANY super common features not spec complaint with no plans to fix. Same with SQL Server. I'm not sufficiently familiar with MySQL/MariaDB to evaluate how closely it tracks the SQL standard. It seems to claim only minor deviations, but that may well be from not claiming conformance at all with features it has implemented but differently from the standard.
- hot_gril 3y agoBut what are you going to use this for besides Postgres? Nothing else adheres to the standard, and if it did, there'd be no point in using it over Postgres. In my experience, it's been fine to marry a particular DBMS and deal with code changes in the worst case that you have to switch, which would probably be a huge rework either way.
- mananaysiempre 3y ago> A design like libpq, ODBC, etc where the sql syntax needs to be parsed at runtime rather than compile time is considered "dynamic sql" by the standard, and the standard acts like it is less likely to be provided than this interface. Obviously that is hogwash. Yet the “static” variant sounds like a match made in heaven for optimizations that need to know the specific queries you are going to be making ahead of time, like Noria (Materialize.io, etc.). So maybe not so dumb after all, whatever its actual popularity.
- cozzyd 3y agoBut.. you can use stored procedures right?
- chasil 3y agoTo place a name on "another" DB, this is a reimplementation of Oracle Pro*C. Oracle also has Pro*COBOL. https://www.oracle.com/database/technologies/instant-client/precompiler-downloads.html https://www.oracle.com/database/technologies/instant-client/...
- lmz 3y agoAnd SQLJ for Java should you want that: https://docs.oracle.com/database/121/JSQLJ/overview.htm#JSQLJ136 https://docs.oracle.com/database/121/JSQLJ/overview.htm#JSQL...
- jpgvm 3y agoI will now use this opportunity to bitch about Oracle not supporting the BOOLEAN SQL type. Also ''=NULL. </bitch>