0

I was running these codes in TiDB:

CREATE FUNCTION `FN_UP_TRADEDAY`(
endDay int(11),
upDays int(11),
marketx varchar(20)
) RETURNS int(11)
READS SQL DATA
BEGIN

declare beginDay int(11);
declare days int(11) default upDays-1;

select
day into beginDay
from t_tradeday
where market = marketx and day <= endDay
order by day desc limit days, 1;

RETURN beginDay;
END;

But I can't create the function and get an error message: "[Err] 1105 - line 1 column 15 near FN_UP_TRADEDAY". Why?

Coco
  • 29
  • 4

1 Answers1

1

I did not find a specific description for creating functions in TiDB, so I can assume that the standard syntax of SQL is used.

So, you shouldn't use quotes ' in function name. After returns there is string READS SQL DATA, seems like it's comment, so add -- before, for escaping it.

Anton Gorbunov
  • 1,414
  • 3
  • 16
  • 24