Skip to content

Instantly share code, notes, and snippets.

@sploiselle
Last active June 3, 2016 19:36
Show Gist options
  • Save sploiselle/ab36562fd19543ef844db43781e8331e to your computer and use it in GitHub Desktop.
Save sploiselle/ab36562fd19543ef844db43781e8331e to your computer and use it in GitHub Desktop.
DELETE SQL statement IDENT clause

##Problem solved! RaduBerinde @RaduBerinde 12:08

Yeah, the IDENT is coming from the grammar which allows you to sometimes not use AS (just col_label)

https://github.com/cockroachdb/cockroach/blob/master/sql/parser/sql.y#L4119

RaduBerinde @RaduBerinde 12:19

I think it's means it cannot be any SQL keyword

##Needless details

##STEPS TO REPRO IDENT CLAUSE BEHAVIOR

> CREATE TABLE account_information (
   account_id INT PRIMARY KEY NOT NULL, 
   balance DECIMAL, 
   account_holder STRING(50)
   );
   
> INSERT INTO account_information VALUES
   (1, 32000, 'Nyla Nasser'),
   (2, 25000, 'Leonie Tietmeyer')
   ;

Based on the SQL track, this is the correct spot for the IDENT clause (RETURNING a_expr IDENT):

> DELETE FROM account_information WHERE account_id=1 RETURNING balance IDENT;
+-------+
| IDENT |
+-------+
| 32000 |
+-------+

As you can see, all it does is function like AS col_label, which we can show is the behavior of all strings placed after the a_expr

> DELETE FROM account_information WHERE account_id=2 RETURNING balance colVarName123;
+---------------+
| colVarName123 |
+---------------+
|         25000 |
+---------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment