Basically 2. Note that SqlWriter has a method fetchOffset(SqlNode fetch, 
SqlNode offset) which calls SqlDialect.unparseOffsetFetch(SqlWriter writer, 
SqlNode offset, SqlNode fetch). I think you should add 
SqlDialect.unparseTop(SqlWriter writer, SqlNode offset, SqlNode fetch) which 
will no-op for all dialects except Sybase.

Suppose you want to get at most 5 rows from table T1 union table T2. In 
standard SQL you’d write

  SELECT * FROM T1
  UNION
  SELECT * FROM T2
  FETCH 5;

and note that the “FETCH 5”  applies to the whole UNION, not just T2. I’m not 
sure how you would phrase that in Sybase, but you should handle that case.

Julian


> On Jun 18, 2019, at 12:30 PM, Andrei Sereda <[email protected]> wrote:
> 
> Hello,
> 
> I'm trying to add limit / offset support to Sybase (v11) dialect.
> Unfortunately sybase syntax is not standard [1] (before v12 at least)
> compared to other dialects.
> 
> Example
> ```sql
> select * from table LIMIT 10 OFFSET 5 -- standard SQL
> select TOP 10 START AT 5 * from table -- Sybase
> ```
> 
> SqlSelectOperator [2] has unparsing of LIMIT / OFFSET at the end. Which
> makes it difficult to inject custom SqlNode(s).
> 
> What is the recommended way to deal with this?
> 
> 1) Custom SqlSelectOperator for Sybase
> 2) Splitting SqlSelectOperator.unparse() to be more customizable
> 3) Adding special SqlNode(s) to SqlSelect.selectList
> 4) Adding special SqlNode(s) to SqlSelect.keywordList
> 
> Thanks,
> Andrei.
> 
> [1] http://dcx.sybase.com/1100/en/dbusage_en11/first-order-formatting.html
> [2]
> https://github.com/apache/calcite/blob/9721283bd0ce46a337f51a3691585cca8003e399/core/src/main/java/org/apache/calcite/sql/SqlSelectOperator.java#L133

Reply via email to