sql-parser icon indicating copy to clipboard operation
sql-parser copied to clipboard

support for negative number

Open JoyBinY opened this issue 3 years ago • 5 comments

JoyBinY avatar May 30 '22 07:05 JoyBinY

Could you please provide some context for the adaptation? In most cases, negative numbers should be treated as unary minus plus unsigned integer, resulting in the correct result. Is there a scenario we are not covering yet? By solely changing the lexer rule, I'm afraid that we end up enabling negative numbers for, e.g., VARCHAR/CHARACTER VARYING.

dey4ss avatar Jun 03 '22 15:06 dey4ss

hi, and how to represent a negative number ? insert into persons(id, name, age, money) values (-200, 'write', -17.8, -23.45); the sql like this is not correct . please show me the right sql, thank you !

JoyBinY avatar Jun 06 '22 08:06 JoyBinY

I could reproduce the error and opened an issue for it. We will discuss on what is the best solution for a fix.

dey4ss avatar Jun 06 '22 15:06 dey4ss

we develop our database system base on sql-parser, and we do not know how to insert a negative number, so we edit the lexer rule. on the current situation, is there any ways to add negative numbers ?

JoyBinY avatar Jun 08 '22 02:06 JoyBinY

@JoyBinY A simple fix (which is, however, not 100% correct) is changing -insert_statement : INSERT INTO table_name opt_column_list VALUES '(' literal_list ')' { +insert_statement : INSERT INTO table_name opt_column_list VALUES '(' expr_list ')' { in /src/parser/bison_parser.y line 675. Without changing the parser, you could try another insert syntax: insert into t select -1, -4, 'str' from dummy;

Otherwise, we will update the parser within the next weeks (see #213)

klauck avatar Jun 08 '22 08:06 klauck