Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: support for SELECT with no projections #83255

Closed
Tracked by #8788
jordanlewis opened this issue Jun 23, 2022 · 2 comments · Fixed by #116835
Closed
Tracked by #8788

sql: support for SELECT with no projections #83255

jordanlewis opened this issue Jun 23, 2022 · 2 comments · Fixed by #116835
Assignees
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-tools-hasura C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team
Projects

Comments

@jordanlewis
Copy link
Member

jordanlewis commented Jun 23, 2022

Postgres allows this syntax to SELECT from a table with no projections.

jordan=# CREATE TABLE a (a int); INSERT INTO a VALUES(1);
CREATE TABLE
INSERT 0 1

jordan=# SELECT FROM a;
--
(1 row)

This is not supported by CockroachDB.

Jira issue: CRDB-16953

@jordanlewis jordanlewis added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-pgcompat Semantic compatibility with PostgreSQL labels Jun 23, 2022
@jordanlewis jordanlewis added this to Triage in SQL Queries via automation Jun 23, 2022
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Jun 23, 2022
@knz
Copy link
Contributor

knz commented Jun 24, 2022

I found that the following patch immediately delivers the functionality, without any other change:

diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y
index 64cec45f2e..438b25f390 100644
--- a/pkg/sql/parser/sql.y
+++ b/pkg/sql/parser/sql.y
@@ -1298,7 +1298,7 @@ func (u *sqlSymUnion) asTenantClause() tree.TenantID {
 %type <*tree.Tuple> expr_tuple1_ambiguous expr_tuple_unambiguous
 %type <tree.NameList> attrs
 %type <[]string> session_var_parts
-%type <tree.SelectExprs> target_list
+%type <tree.SelectExprs> target_list opt_target_list
 %type <tree.UpdateExprs> set_clause_list
 %type <*tree.UpdateExpr> set_clause multiple_set_clause
 %type <tree.ArraySubscripts> array_subscripts
@@ -10144,7 +10144,7 @@ simple_select:
 //        [ OFFSET <expr> [ ROW | ROWS ] ]
 // %SeeAlso: WEBDOCS/select-clause.html
 simple_select_clause:
-  SELECT opt_all_clause target_list
+  SELECT opt_all_clause opt_target_list
     from_clause opt_where_clause
     group_clause having_clause window_clause
   {
@@ -10183,10 +10183,9 @@ simple_select_clause:
       Where:      tree.NewWhere(tree.AstWhere, $5.expr()),
       GroupBy:    $6.groupBy(),
       Having:     tree.NewWhere(tree.AstHaving, $7.expr()),
       Window:     $8.window(),
     }
   }
-| SELECT error // SHOW HELP: SELECT

 set_operation:
   select_clause UNION all_or_distinct select_clause
@@ -13486,6 +13485,10 @@ opt_asymmetric:
   ASYMMETRIC {}
 | /* EMPTY */ {}

+opt_target_list:
+  target_list { $$.val = $1.selExprs() }
+| /* EMPTY */ { $$.val = tree.SelectExprs{} }
+
 target_list:
   target_elem
   {

However, I am bummed out that it requires removing the SELECT error branch, which removes both error handling and the CLI interactive help.

I wasn't able to find a way to keep the error clause; I suspect (given the error with it is shift/reduce) there is something to do with a %prec clause, but I couldn't find it.

@ZhouXing19
Copy link
Collaborator

Hi query team, this feature is also needed by Hasura Graphql Engine. They have a workaround already, but still curious do we have a timeline for supporting this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-pgcompat Semantic compatibility with PostgreSQL A-tools-hasura C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team
Projects
Archived in project
SQL Queries
Backlog (DO NOT ADD NEW ISSUES)
Development

Successfully merging a pull request may close this issue.

4 participants