15

Dealing with SQL shows us some limitations and gives us an opportunity to imagine what could be.

Which improvements to SQL are you waiting for? Which would you put on top of the wish list?

I think it can be nice if you post in your answer the database your feature request lacks.

1
  • 2
    Mainly what I would like to see is some attempt to remove much of the cruft that has crept into various dialects of SQL (many anti-relational), making them more incompatible and complex.
    – dkretz
    Jul 16, 2009 at 20:55

46 Answers 46

22

T-SQL Specific: A decent way to select from a result set returned by a stored procedure that doesn't involve putting it into a temporary table or using some obscure function.

SELECT * FROM EXEC [master].[dbo].[xp_readerrorlog]
2
  • You can use parameterised views or a table based function to do the same thing. What would you do if the stored procedure returned multiple recordsets?
    – Guy
    Feb 5, 2009 at 23:11
  • Sybase SQL Anywhere has had this feature for several years. Feb 5, 2009 at 23:27
18

I know it's wildly unrealistic, but I wish they'd make the syntax of INSERT and UPDATE consistent. Talk about gratuitous non-orthogonality.

4
  • Lord yes. Seconded (and thirded if I could!) Feb 5, 2009 at 22:46
  • Example would be INSERT INTO mytable SET field1 = 'this', field2 = 'would', field3 = 'so cool'; I'd also like a WHERE clause on this INSERT form too so you don't have to wrap it in an IF statement.
    – Guy
    Feb 5, 2009 at 23:14
  • MySQL supports the UPDATE syntax in INSERT, though it would be good if they all supported that. :-)
    – staticsan
    Feb 6, 2009 at 5:58
  • I always liked the insert statement syntax more
    – Cervo
    Jun 23, 2010 at 23:06
12

Operator to manage range of dates (or numbers):

where interval(date0, date1) intersects interval(date3, date4) 

EDIT: Date or numbers, of course are the same.

EDIT 2: It seems Oracle have something to go, the undocumented OVERLAPS predicate. More info here.

5
  • I think you can already simulate this with the spatial queries of mysql. See mailund.dk/index.php/2009/01/22/…
    – Pierre
    Feb 5, 2009 at 22:45
  • The OVERLAPS operator (which my PostgreSQL manual seems to claim is part of the SQL standard) will do this for you in PostgreSQL.
    – kquinn
    Feb 5, 2009 at 22:58
  • In Oracle you could do this by creating your own object type and making a table of them. Then you could write an intersects function.
    – WW.
    Feb 5, 2009 at 23:46
  • @Danil, IN BETWEEN is not enought
    – FerranB
    Feb 10, 2009 at 21:35
  • @WW I do it now with packages
    – FerranB
    Feb 10, 2009 at 23:03
10

A decent way of walking a tree with hierarchical data. Oracle has CONNECT BY but the simple and common structure of storing an object and a self-referential join back to the table for 'parent' is hard to query in a natural way.

5
  • I assume you're familiar with using 'nested sets', i.e. using 'left' and 'right' values in the table to identify node locations.
    – ChrisW
    Jan 23, 2009 at 21:56
  • Yep and it's damned ugly, error-prone and slow for inserts/deletes/moves.
    – cletus
    Jan 23, 2009 at 21:59
  • Completely agree. Better tools for managing hierarchical data is the top of my wish-list. Nested sets work sometimes, but they complicate the situation and of course are horrible for frequently updated trees.
    – chroder
    Jan 28, 2009 at 0:34
  • 1
    The SQL standard specifies recursive SQL, through recursive "common table expresseions" (CTEs). DB2, MSSQL and (soon also Oracle, I've heard) have it. Feb 5, 2009 at 22:16
  • This is available in MS SQL 2008 now. msdn.microsoft.com/en-us/magazine/cc794278.aspx
    – JohnFx
    Feb 5, 2009 at 22:44
9

More SQL Server than SQL but better integration with Source Control. Preferably SVN rather than VSS.

2
  • That's what Team Edition for Database Professionals is. Which has been rolled into Team Edition for Developers.
    – NotMe
    Jan 23, 2009 at 22:45
  • Although, the management studio supposedly has support for a source control plug-in. However it doesn't work with TFS.
    – NotMe
    Jan 25, 2009 at 20:40
7

Implicit joins or what it should be called (That is, predefined views bound to the table definition)

SELECT CUSTOMERID, SUM(C.ORDERS.LINES.VALUE) FROM CUSTOMER C

A redesign of the whole GROUP BY thing so that every expression in the SELECT clause doesn't have to be repeated in the GROUP BY clause

Some support for let expressions or otherwise more legal places to use an alias, a bit related to the GROUP BY thing, but I find other times what I just hate Oracle for forcing me to use an outer select just to reference a big expression by alias.

6

I would like to see the ability to use Regular Expressions in string handling.

4
  • SQL Server kinda does it, not natively but a user defined function as explained in sqlteam.com/article/regular-expressions-in-t-sql is certainly better than nothing...
    – tekiegreg
    Feb 5, 2009 at 22:23
  • @tekiegreg: after an admittedly quick read, that appears to be only for searching, not replacing.
    – BoltBait
    Feb 5, 2009 at 22:26
  • The SQL standard has regular expressions. And many DBMSes support it, but I'm not sure if anyone has found an efficient way of supporting it, e.g. special regex-friendly indexing. Feb 5, 2009 at 22:34
  • @Troels Arvan, You can use function based indexes in Oracle (see here: dba-oracle.com/t_regular_expressions_tuning_index.htm )
    – tuinstoel
    Mar 19, 2009 at 21:14
5

A way of dynamically specifying columns/tables without having to resort to full dynamic sql that executes in another context.

4

Ability to define columns based on other columns ad infinitum (including disambiguation).

This is a contrived example and not a real world case, but I think you'll see where I'm going:

SELECT LTRIM(t1.a) AS [a.new]
    ,REPLICATE(' ', 20 - LEN([a.new])) + [a.new] AS [a.conformed]
    ,LEN([a.conformed]) as [a.length]
FROM t1
INNER JOIN TABLE t2
    ON [a.new] = t2.a
ORDER BY [a.new]

instead of:

SELECT LTRIM(t1.a) AS [a.new]
    ,REPLICATE(' ', 20 - LEN(LTRIM(t1.a))) + LTRIM(t1.a) AS [a.conformed]
    ,LEN(REPLICATE(' ', 20 - LEN(LTRIM(t1.a))) + LTRIM(t1.a)) as [a.length]
FROM t1
INNER JOIN TABLE t2
    ON LTRIM(t1.a) = t2.a
ORDER BY LTRIM(t1.a)

Right now, in SQL Server 2005 and up, I would use a CTE and build up in successive layers.

4

I'd like the vendors to actually standardise their SQL. They're all guilty of it. The LIMIT/OFFSET clause from MySQL and PostGresql is a good solution that no-one else appears to do. Oracle has it's own syntax for explicit JOINs whilst everyone else uses ANSI-92. MySQL should deprecate the CONCAT() function and use || like everyone else. And there are numerous clauses and statements that are outside the standard that could be wider spread. MySQL's REPLACE is a good example. There's more, with issues about casting and comparing types, quirks of column types, sequences, etc etc etc.

3
  • 1
    LIMIT/OFFSET is standardized, see troels.arvin.dk/db/rdbms/#select-limit-offset A MySQL-like REPLACE is standardized, as well, in the MERGE construct. So actually, a lot things have been standardized (sometimes for a long time), but users need to ask their DBMS producer to support it... Sep 7, 2009 at 20:10
  • ... which really goes back to my original point: the vendors need to standardise their SQL :-). But thanks for the link. I had seen it years ago but wasn't aware you were updating it.
    – staticsan
    Sep 9, 2009 at 3:14
  • SQL Server should deprecate the + operator and use || like everyone else. Mar 19, 2010 at 20:23
4

parameterized order by, as in:


select * from tableA order by @columName
1
  • You can do this with a CASE statement already, and it would be less ambiguous.
    – Guy
    Feb 5, 2009 at 23:18
3

Support in SQL to specify if you want your query plan to be optimized to return the first rows quickly, or all rows quickly.

Oracle has the concept of FIRST_ROWS hint, but a standard approach in the language would be useful.

1
  • In SQL Server you can use "OPTION (Fast n)" to say you want the first n rows quickly. Mar 20, 2009 at 18:32
3

Automatic denormalization.

But I may be dreaming.

5
  • Not sure why the downvote. What if your RDMS could recognize that you are probably going to query for SUM(LineItemAmount) GROUP BY InvoiceId and keep that total internally somehow automagically?
    – WW.
    Feb 6, 2009 at 0:24
  • Probably someone who's just been introduced to databases thinking "omgz denormalization is ALWAYS bad!!!!" Feb 6, 2009 at 1:09
  • +1 that's not a terrible idea. I'm not sure I'd want to to actually be automatic, but it could be as automatic as indexes. the db does it when it knows it has to, and also when you ask it to. Jul 13, 2009 at 23:34
  • Yes. Bad wording but you got my drift. Jul 14, 2009 at 4:08
  • What if ORMs did this? The ORM could write the SP to denormalize the relationship when the developer writes the condition to do so. That's less work for (or waiting on) the DBA, and more power to the DB to optimize such operations internally. The DB would spend less time creating or reading statistics, because lookup operations could be optimized through SP logic.
    – northben
    Feb 28, 2015 at 5:57
2

Improved pivot tables. I'd like to tell it to automatically create the columns based on the keys found in the data.

1
  • I posted the same thing... let us do a subselect instead of having to use dynamic SQL. Please.
    – BoltBait
    Feb 5, 2009 at 22:23
2

On my wish list is a database supporting sub-queries in CHECK-constraints, without having to rely on materialized view tricks. And a database which supports the SQL standard's "assertions", i.e. constraints which may span more than one table.

Something else: A metadata-related function which would return the possible values of a given column, if the set of possible values is low. I.e., if a column has a foreign key to another column, it would return the existing values in the column being referred to. Of if the column has a CHECK-constraint like "CHECK foo IN(1,2,3)", it would return 1,2,3. This would make it easier to create GUI elements based on a table schema: If the function returned a list of two values, the programmer could decide that a radio button widget would be relevant - or if the function returned - e.g. - 10 values, the application showed a dropdown-widget instead. Etc.

2

UPSERT or MERGE in PostgreSQL. It's the one feature whose absence just boggles my mind. Postgres has everything else; why can't they get their act together and implement it, even in limited form?

2

Check constraints with subqueries, I mean something like:

CHECK ( 1 > (SELECT COUNT(*) FROM TABLE WHERE A = COLUMN))
2

These are all MS Sql Server/T-SQL specific:

  1. "Natural" joins based on an existing Foreign Key relationship.
  2. Easily use a stored proc result as a resultset
  3. Some other loop construct besides while
  4. Unique constraints across non NULL values
  5. EXCEPT, IN, ALL clauses instead of LEFT|RIGHT JOIN WHERE x IS [NOT] NULL
  6. Schema bound stored proc (to ease #2)
  7. Relationships, schema bound views, etc. across multiple databases
2

WITH clause for other statements other than SELECT, it means for UPDATE and DELETE.

For instance:

WITH table as (
  SELECT ...
)
DELETE from table2 where not exists (SELECT ...)
2

Something which I call REFERENCE JOIN. It joins two tables together by implicitly using the FOREIGN KEY...REFERENCES constraint between them.

2

A relational algebra DIVIDE operator. I hate always having to re-think how to do all elements of table a that are in all of given from table B.

http://www.tc.umn.edu/~hause011/code/SQLexample.txt

1

String Agregation on Group by (In Oracle is possible with this trick):

SELECT deptno, string_agg(ename) AS employees
FROM   emp
GROUP BY deptno;

DEPTNO EMPLOYEES
---------- --------------------------------------------------
    10 CLARK,KING,MILLER
    20 SMITH,FORD,ADAMS,SCOTT,JONES
    30 ALLEN,BLAKE,MARTIN,TURNER,JAMES,WARD
2
  • SQL Anywhere supports the LIST function that does this. You can even specify ordering and the delimiter. Feb 5, 2009 at 23:31
  • I swear by that function in a lot of cases. Mar 17, 2009 at 15:50
1

More OOP features:

  • stored procedures and user functions

    CREATE PROCEDURE tablename.spname ( params ) AS ...

called via

EXECUTE spname
FROM tablename
WHERE conditions
ORDER BY

which implicitly passes a cursor or a current record to the SP. (similar to inserted and deleted pseudo-tables)

  • table definitions with inheritance

table definition as derived from base table, inheriting common columns etc

Btw, this is not necessarily real OOP, but only syntactic sugar on existing technology, but it would simplify development a lot.

1
1

Abstract tables and sub-classing

create abstract table person
  (
  id primary key,
   name varchar(50)
  );

create table concretePerson extends person
  (
  birth date,
  death date
  );

create table fictionalCharacter  extends person
  (
  creator int references concretePerson.id      
  );
3
  • Doesn't Postgres already do this to some extent with derived tables? Feb 9, 2009 at 23:07
  • You can already much get that using 1-to-1 relationships, so that would just be syntatic sugar for insert/update operations. Still, it would be useful. Mar 19, 2009 at 21:10
  • This is possible with Oracle, you can define types that inherit from another type.
    – tuinstoel
    Mar 19, 2009 at 21:18
1

Increased temporal database support in Sql Server. Intervals, overlaps, etc.

Increased OVER support in Sql Server, including LAG, LEAD, and TOP.

1

Arrays

I'm not sure what's holding this back but lack of arrays lead to temp tables and related mess.

2
1

Some kind of UPGRADE table which allows to make changes on the table to be like the given:

CREATE OR UPGRADE TABLE 
( 
  a VARCHAR,
  ---
)
1

My wish list (for SQLServer)

  1. Ability to store/use multiple execution plans for a stored procedure concurrently and have the system automatically understand the best stored plan to use at each execution.

Currently theres one plan - if it is no longer optimal its used anyway or a brand new one is computed in its place.

  1. Native UTF-8 storage

  2. Database mirroring with more than one standby server and the ability to use a recovery model approaching 'simple' provided of course all servers are up and the transaction commits everywhere.

  3. PCRE in replace functions

  4. Some clever way of reusing fragments of large sql queries, stored match conditions, select conditions...etc. Similiar to functions but actually implemented more like preprocessor macros.

0
1

Comments for check constraints. With this feature, an application (or the database itself when raising an error) can query the metadata and retrieve that comment to show it to the user.

2
  • This would be excellent for ALL constraints. Best idea ever. No more parameter verification, just try to do your stuff and show the message for any violated constraint. For a more lightweight solution, just associating each constraint with an integer or GUID might be good enough
    – erikkallen
    Mar 19, 2009 at 21:42
  • You can already name constraints when you create them, so given a proper naming convention, the app can actually use the constraint name in a relevant way. (I've actually used this.) But of course, this could be improved. DB2 (and other DBMSes) have a COMMENT ON construct which can be used for just about any DB object, perhaps including constraints; that's worth standardizing. Sep 7, 2009 at 20:16
1

Automated dba notification in the case where the optimizer generates a plan different that the plan that that the query was tested with.

In other words, every query can be registered. At that time, the plan is saved. Later when the query is executed, if there is a change to the plan, the dba receives a notice, that something unexpected occurred.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.