views:

1086

answers:

46

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.

+10  A: 

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.

cletus
I assume you're familiar with using 'nested sets', i.e. using 'left' and 'right' values in the table to identify node locations.
ChrisW
Yep and it's damned ugly, error-prone and slow for inserts/deletes/moves.
cletus
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.
Christopher Nadeau
The SQL standard specifies recursive SQL, through recursive "common table expresseions" (CTEs). DB2, MSSQL and (soon also Oracle, I've heard) have it.
Troels Arvin
This is available in MS SQL 2008 now.http://msdn.microsoft.com/en-us/magazine/cc794278.aspx
JohnFx
+9  A: 

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

Tom Ritter
That's what Team Edition for Database Professionals is. Which has been rolled into Team Edition for Developers.
Chris Lively
Although, the management studio supposedly has support for a source control plug-in. However it doesn't work with TFS.
Chris Lively
+20  A: 

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]
Dalin Seivewright
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
Sybase SQL Anywhere has had this feature for several years.
Graeme Perrow
You can use APPLY FROM
Vincent Buck
+3  A: 

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.

Alan
In SQL Server you can use "OPTION (Fast n)" to say you want the first n rows quickly.
Jonathan Allen
+5  A: 

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

Cervo
+2  A: 

Automatic denormalization.

But I may be dreaming.

Spencer Ruport
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
Probably someone who's just been introduced to databases thinking "omgz denormalization is ALWAYS bad!!!!"
Spencer Ruport
+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.
TokenMacGuy
Yes. Bad wording but you got my drift.
Spencer Ruport
A: 

Clean way to enforce optimal execution plan.

There are hints in MSSQL and Oracle, but you need to persuade the DBMS to use them, they can be silently ignored, and this is cited as a feature, not a bug in documentation.

Quassnoi
I politey disagree, what happens if using a specified Index for a particular query is just wrong no matter how you slice it? Should the DBMS in question shoot itself in the foot anyways, even if it knows better? I say no...
tekiegreg
A well formed Oracle hint is never ignored, so long as there is some plan using that hint which can provide the correct answer. SELECT /*+ SHOOT(FOOT) */
WW
People, you seriously think I know nothing of hints and wrote it just to be there? DBMS in question should shoot feet and asses if I say so, it's a tool, I'm the boss. A well formed Oracle hint is all nice and stuff, but they are limited in number, I can't add mine, and PL/SQL is just slow.
Quassnoi
Whenever I've put in a bad hint in MSSQL, it's always given me an error or used a sub-optimal plan instead of ignoring it.
Chris Smith
This is called a Plan Guide in SQL Server: http://msdn.microsoft.com/en-us/library/ms187032(SQL.90).aspx
Dave Markle
+2  A: 

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

Chris Lively
I posted the same thing... let us do a subselect instead of having to use dynamic SQL. Please.
BoltBait
+7  A: 

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.

John Nilsson
+11  A: 

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.

FerranB
I think you can already simulate this with the spatial queries of mysql. See http://www.mailund.dk/index.php/2009/01/22/playing-with-spatial-queries-in-mysql/
Pierre
The OVERLAPS operator (which my PostgreSQL manual seems to claim is part of the SQL standard) will do this for you in PostgreSQL.
kquinn
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
@Danil, IN BETWEEN is not enought
FerranB
@WW I do it now with packages
FerranB
+1  A: 

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
FerranB
SQL Anywhere supports the LIST function that does this. You can even specify ordering and the delimiter.
Graeme Perrow
I swear by that function in a lot of cases.
Lurker Indeed
A: 

Optimizing QBE (Query By Example). Finally giving us a way to pass off responsibility to the database for all those queries that want to match on an arbitrary subset of columns.


EDIT: QBE is a non-SQL methodology for querying relational data. To add it to SQL would maybe look something like

SELECT columns
FROM table
WHERE EXAMPLE (firstname, lastname, birthdate) = ('Fred%', 'Jones', '20090209')

Functionally to support something like what Access has for the graphical querydef designer. You give it a list of fields, and collect a set of matching user inputs, and the optimizer would toss out the columns not specified and optimize on the rest.

le dorfier
Don't all the databases already do this? Or are you saying they need to do it better?
WW
+4  A: 

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.

Cade Roux
A: 

Foreing keys that manage interval dates on other tables

For instance, for tables:

TABLE_A(begin DATE, end DATE)
TABLE_B(day DATE)

Some way to define On TABLE_B:

FOREIGN KEY (day)
  REFERENCES INTERVAL ON TABLE_A (begin, endd)
FerranB
A: 

Efficient implementation of SQL standards, such as DOMAINs, for those platforms that don't support them.

JeremyDWill
A: 

Partial Foreing key constraint.

If have those tables:

create table prova_a (a number, b number);
alter table prova_a add primary key (a,b);
create table prova_b (a number, b number);
alter table prova_b add foreign key (a,b) references prova_a(a,b) ;
insert into prova_a  values (1,2);

You can insert this without error:

insert into prova_b  values (123,null);
insert into prova_b  values (null,null);
insert into prova_b  values (null,123);

I wish something to avoid this without using check constraints.

FerranB
I don't think your examples are correct. 123 does not appear in prova_a at all.
WW
@WW That's the question. SQL Standard says it's ok. But I don't like ;-)
FerranB
+6  A: 

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

BoltBait
Oracle does it ;-)
FerranB
Don't tease me. :(
BoltBait
SQL Server kinda does it, not natively but a user defined function as explained in http://www.sqlteam.com/article/regular-expressions-in-t-sql is certainly better than nothing...
tekiegreg
@tekiegreg: after an admittedly quick read, that appears to be only for searching, not replacing.
BoltBait
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.
Troels Arvin
@Troels Arvan, You can use function based indexes in Oracle (see here: http://www.dba-oracle.com/t_regular_expressions_tuning_index.htm )
tuinstoel
+2  A: 

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.

Troels Arvin
+17  A: 

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

catfood
Lord yes. Seconded (and thirded if I could!)
Electrons_Ahoy
Example would be INSERT INTO mytableSET 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
MySQL supports the UPDATE syntax in INSERT, though it would be good if they *all* supported that. :-)
staticsan
I always liked the insert statement syntax more
Cervo
A: 

LINQ-like functionalities integration to SQL :-)

MarlonRibunal
What do you miss? Examples?
tuinstoel
+1  A: 

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.

devio
Hey, Postgres has table inheritance.
Michał Rudnicki
+1  A: 

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      
  );
Pierre
This would be cool.
Chris Lively
Doesn't Postgres already do this to some extent with derived tables?
Chris Smith
I don't know but It is good to know. Thanks
Pierre
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.
Jonathan Allen
This is possible with Oracle, you can define types that inherit from another type.
tuinstoel
A: 

select on recursive tables:

   select * from rdfClass where rdfClass.uri is instance of "foaf:Person";
Pierre
A: 

No more record size/command length limits.

BoltBait
+2  A: 

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?

kquinn
+4  A: 

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.

staticsan
Oracle supports ANSI joins
Einstein
LIMIT/OFFSET is standardized, see http://troels.arvin.dk/db/rdbms/#select-limit-offsetA 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...
Troels Arvin
... 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
SQL Server should deprecate the + operator and use || like everyone else.
Lluis Martinez
+4  A: 

parameterized order by, as in:


select * from tableA order by @columName
Kevin
You can do this with a CASE statement already, and it would be less ambiguous.
Guy
Yea, but the case statement sucks performance wise.
Jonathan Allen
A: 

Kevin beat me to it by a couple of seconds... but more generally,

select @columnName from @tableName
order by @otherColumnName

etc

It would render swathes of nasty string concatenation followed by

exec (@sql)

instantly unnecessary.

ChrisA
iBATIS SQL maps are a good way of avoiding nasty string concatenation.
WW
Even just able to do it in a stored procedure would be a plus.
staticsan
+1  A: 

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

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

ShaneD
A: 

SQL Server specific:

Some decent date functions, like TRUNC. Improvements to full text searching (better control over matching logic)

I would LOVE it if SQL server could store different databases within the same database and log files (shared FILEGROUPS) so I can backup the WHOLE server in one go.

Full syntax and error checking of a stored procedure when I compile it (not only when I run it)

Yes, this is starting to sound like "I want all the Oracle features in SQL Server without all the complexity (and cost!)"

Guy
A: 

I would love to see the ability to put a WHERE clause on at index creation time:

CREATE INDEX BAR ON FOO (FooName, FooId) WHERE FooEnabled = 1;

Then, the optimizer could use this when processing SQL like this:

SELECT FooId, FooName
FROM Foo
WHERE FooEnabled = 1
ORDER BY FooName;

This seems like a solvable problem from both the index creation and optimizer perspectives. Indeed, you can simulate the same thing using function based indexes and/or materialized views. This is messy and can involve changing the SQL issued by an application.

It would be nice to have a syntactic sugar above.

WW
This is like index by function.
FerranB
Yes, in Oracle you have to muck around with a function based index to do this. But then you must put the same function in your SQL rather than the more natural form.
WW
A partial index? That's an intruiging idea...
staticsan
can't you sort of already optimize this with `CREATE INDEX BAR ON (FooEnabled, FooId, FooName)`?
TokenMacGuy
@TokenMacGuy: You can, but there are lots of useless entries in there with FooEnabled = 0. If it is a processing queue, this might be 99% of your data.
WW
+1  A: 

Arrays

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

Learning
SQL Server 2008 finally adds those.http://www.code-magazine.com/Article.aspx?quickid=0712122
Jonathan Allen
Also possible with Oracle. Indeed much better than temp tables.
tuinstoel
+2  A: 

Check constraints with subqueries, I mean something like:

CHECK ( 1 > (SELECT COUNT(*) FROM TABLE WHERE A = COLUMN))
FerranB
+1  A: 

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

CREATE OR UPGRADE TABLE 
( 
  a VARCHAR,
  ---
)
FerranB
+1  A: 

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.

Einstein
+2  A: 

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
Mark Brackett
+1  A: 

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.

FerranB
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
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.
Troels Arvin
+2  A: 

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 ...)
FerranB
+2  A: 

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

Barry Brown
A: 

Nested aggregate functions.

PostgreSQL doesn't allow something like SELECT MAX(COUNT(*))...

Barry Brown
What would it mean? You can do (at least in Oracle and SQL server) SELECT MAX(x) FROM (SELECT COUNT(*) x, y FROM t1 GROUP BY y)
erikkallen
A: 

A CreateOrAlter command.

I am sick and tired of changing back and forth between "Create Proc" and "Alter Proc". I don't care if it is create or alter, I just want the end result to be what I put in the body of the procedure.

Jonathan Allen
+1  A: 

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.

EvilTeach
+1  A: 

1) [LEFT | RIGHT] SEMI JOIN and [LEFT | RIGHT] ANTI JOIN These would allow me to write something like

-- return customers who have placed at least one order
SELECT c.*
  FROM Customers c
  LEFT SEMI JOIN o ON o.CustomerId = c.Id

-- return customers who have NOT placed any order
SELECT c.*
  FROM Customers c
  LEFT ANTI JOIN o ON o.CustomerId = c.Id

This would have exactly the same result as

SELECT c.*
  FROM Customers c
 WHERE c.Id IN(SELECT CustomerId FROM Orders)

and

SELECT c.*
  FROM Customers c
 WHERE c.Id NOT IN(SELECT CustomerId FROM Orders)

, respectively. However the IN (or the pretty much equivalent EXISTS) syntax is much messier than my proposed syntax, especially in more complicated cases.

Of course, the semi/anti-joined table can not be referenced so this would be ILLEGAL:

-- Error, can't reference semi joined table.
SELECT c.*, o.OrderNumber
  FROM Customers c
  LEFT SEMI JOIN o ON o.CustomerId = c.Id

2) It woud be nice to have a good solution to the

WHERE Column IN('a', 'b', 'c')

problem when you don't know the number of values to search for. Perhaps it could be possible to allow

WHERE Column IN(ARRAY @array)

and the calling code would bind @array to an array.

Edit: I just thought of one more

3) Some kind of extensibility to the constraint system, which allows coding of constraints between tables which work perfectly in concurrent environments and which lets me manually do any locking and validation to ensure that the constraint is always satisfied. Triggers can be used currently, but they are very hard to get right considering concurrency.

erikkallen
+2  A: 

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

berlin.ab
A: 

Computed columns.

Hability to add columns on table based on an expression for another one without need to create a view.

FerranB
SELECT foo.bar, 3*foo.bar AS baz FROM foo;
TokenMacGuy
A: 

MACRO SQL EXPRESSIONS

For instance:

SELECT *
  FROM X
 WHERE MACRO_1(A, B, C)

Where MACRO_1 can be something like:

A*2/B+C

or something like:

A=2 OR B<C

MACRO_1 is not a function, it's just a macro to be preprocessed and substituted before the final parsing.

They are like functions but because are substituted the optimizer can take advantage of indexes, not like funcions that the optimizer does not know what happens.

FerranB