Besides portability, there is IMHO nothing against INSERT ... ON CONFLICT if it does what you need.
1,995 karma · joined January 17, 2014
All about SQL:
https://winand.at/ https://use-the-index-luke.com/ https://modern-sql.com/
Besides portability, there is IMHO nothing against INSERT ... ON CONFLICT if it does what you need.
It's there already!
It's in the chart as footnote "b": Outer reference must be the only argument (doesn’t support F441)
That's the one thing SQL Server doesn't eat. Those that are green in the chart work fine in this case.
I'd go for CHECK constraints first: https://www.sqlite.org/lang_createtable.html#ckconst
> Procedural SQL [...] Choose your investment here carefully.
I think that the demand for procedual code has dropped drastically in the past decades as the "normal" SQL can solve so many more things with window functions, recursion, and so forth. So I'd say: Yes, choose your investment wisely and stay away from procedural SQL as long as possible.
Can you tell me: what kind of identifier is it (view name, function name) and which SQL context it causes problems (select list, create/drop statement, ...) and which system has problems with it. Thx.
All charts on modern-sql.com are backed by tests. I also keep them up-to-date by running them for new releases when they appear.
Also, which features in particular are you missing in PostgreSQL? Merge was added with PostgreSQL 15 a year ago: https://modern-sql.com/caniuse/merge
It also not aimed at users, but at implementors. Funny enough, they don't read the standard either ;) But more seriously: Some implementations are old and generally vendors prefer not changing the behavior of their product. When the standard comes later, the train has already departed. The most critical incompatibilities are in the elder features. The newer ones have a tendency the be more aligned with standard behavior (e.g. window functions are typically implemented just fine).
> They haven't gotten as far as working out variables or function composition either [0].
Part 2 SQL[0] is declarative and intentionally doesn't have variables. Part 4 SQL (aka "pl" SQL) does have variables. I personally consider Part 4 obsolete on systems that have sufficient modern Part 2 support.
> Tying SQL to your specific database is the best option for performance. Writing database-independent SQL is somethign of a fools errand, it is either trivial performance-insensitive enough that you should be using a code generator or complex enough to deserve DB-specific turning.
While this is certainly true for some cases there are also plenty of examples where the standard SQL is more concise and less error prone than product-specific alternatives. E.g. there COALESCE is the way to go rather than isnull, ifnull, nvl, or the like (typically limited to two arguments, sometimes strange treatment of different types).
There is a lot of *unnecessary* vendor-lock in in the field.
There I also look at limitations of some implementations and problems such as not reporting ambiguous column names — just guessing what you mean ;)
But thanks for the feedback. There is a rework pending anyway.
Having that said: free would be better.
A problem everbody would love to have but pretty much nobody actually has.
- SQL/PGQ - A Graph Query Language
- JSON improvements (a JSON type, simplified notations)
Peter Eisentraut gives a nice overview here: https://peter.eisentraut.org/blog/2023/04/04/sql-2023-is-fin...
Includes an updates version of the first slideset: https://modern-sql.com/slides/ModernSQL-2019-05-30.pdf
E.g (made-up syntax)
CREATE TEMPLATE VIEW numbered_by_ts(t1) AS (
SELECT t1.*
, ROW_NUMBER() OVER(ORDER BY ts) AS rn
FROM t1
)
e.g. use it like this: SELECT *
FROM numbered_by_ts(table_name);
I think they should behave more like C++ templates rather than C pre-processor makros[1], thus I used the keyword TEMPLATE in CREATE VIEW. If you provide a table that doesn't have a column TS, it would be a syntax error, just like it is with C++ templates.With common table expressions it would be easily possible to inject entire subqueries into the template view:
WITH cte AS (SELECT ... FROM ...)
SELECT *
FROM numbered_by_ts(cte);
For completness, WITH queries should also be allowed to be TEMPLATEs.Speaking of the WITH clause, SQLite support ploymorphic views because SQLite CTEs are visible in elements that are "generally contained"[2] in the statement (the SQL standard defines it differently[3]).
Example:
CREATE TABLE t1 (
ts TIMESTAMP
);
INSERT INTO t1 VALUES ('2000-01-01 00:00:00');
CREATE VIEW numbered_by_ts AS
SELECT t1.*
, ROW_NUMBER() OVER(ORDER BY ts) AS rn
FROM t1
;
CREATE TABLE ta (
ts TIMESTAMP
);
INSERT INTO ta VALUES ('2010-01-01 00:00:00');
CREATE TABLE tb (
no_ts TIMESTAMP
);
INSERT INTO tb VALUES ('2020-01-01 00:00:00');
SELECT * FROM numbered_by_ts;
-- accesses t1, resturns year 2000
WITH t1 AS (SELECT * FROM ta)
SELECT * FROM numbered_by_ts;
-- accesses ta, resturns year 2010
WITH t1 AS (SELECT * FROM tb)
SELECT * FROM numbered_by_ts;
-- syntax error: no "ts" column in tb
SQLite is the only system I know of that implements WITH like that. See "views bypass with" here: https://modern-sql.com/feature/with#compatibilityThe polymorpic table functions, as introduced by SQL:2016, might be able to accomplish all of that but for me they feel like using a sledgehamer for cracking a nut.
[1] As far as I understand the Oracle 20c SQL makros behave like C pre-processor makros.
[2] "Generally contain" as defined by "Syntactic containment" in ISO/IEC 9075-1. The 2011 version of that can be downloaded for free at ISO: http://standards.iso.org/ittf/PubliclyAvailableStandards/c05...
[3] ISO/IEC 9075-2, "<query expression>": the definition of "query name in scope" says "contained", not "generally contained".
E.g.
GROUP BY tenant
, GROUPING SETS ( (year, month)
, (year)
)
is equivalant to GROUP BY GROUPING SETS ( (tenant, year, month)
, (tenant, year)
)
and GROUP BY tenant, year
, GROUPING SETS ( (month)
, ()
)
(however, I find the last one odd: I like to keep the "tenant" part seperate from the actual grupings you'd like to do).https://modern-sql.com/use-case/literate-sql
Something like "polymorpihc" views would be extremley useful, but is not there yet (in standard SQL).
In other areas there are sublte features like the explicit WINDOW clause to avoid repeating similar OVER clauses. Breifly mentioned at the end of this doc:
https://www.postgresql.org/docs/current/tutorial-window.html
This was adopted in recent years by many FOSS-DBs, but not yet by the big commercial ones:
https://modern-sql.com/static/sm-blog-2019-postgesql-11.over...
Similarily the chaining of grouping sets can be helpful in those very rare cases you need them.
The Oracle Database intrdouced "SQL Macros" recently. For my taste, they are too 'rude' to make me happy on first sight (much like C #define):
https://blog.dbi-services.com/oracle-20c-sql-macros-a-scalar...
Ups, if this is you take away, then I've done something wrong.
Let me correct that: The order of columns in an index matters, not the order of conditions in the where clause.
SQL has nested relations since SQL:2003[1] (called multisets). They are not widley supported and frankly speaking I don't like them.
JSON was finally added with SQL:2016[2].
[1] https://sigmodrecord.org/publications/sigmodRecord/0403/E.Ji...
[2] https://modern-sql.com/blog/2017-06/whats-new-in-sql-2016#js...
One of my test cases was binding that paramter as 'numeric' rather than 'interger'. The other DBs didn't care about that.