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

DELETEoffset > 0 rule in OrderWithOffsetFetchSQL #429

Open
nek1kek opened this issue Sep 5, 2024 · 0 comments
Open

DELETEoffset > 0 rule in OrderWithOffsetFetchSQL #429

nek1kek opened this issue Sep 5, 2024 · 0 comments

Comments

@nek1kek
Copy link

nek1kek commented Sep 5, 2024

In my project I have Oracle 19c, that do not know about LIMIT command.

But cuz I want pagination, I decided to make query like this:

SELECT col_1, col_2
FROM my_table 
WHERE ...
-- under K and N is values
OFFSET :K ROWS -- word ROWS required
FETCH NEXT :N ROWS ONLY

So if K = 0, I have same work as with LIMIT, and if K > 0 I have pagination rule.
But with this rule I can not do this, so i write special func:

func addPagination2Query(query string, args []any, limit, offset uint) (string, []any) {
	/*
		thx oracle for this PITA:
			We can`t use goqu function(offset + fetch), cuz oracle want to add ROW|ROW|NEXT after value.
			https://docs.oracle.com/en/database/oracle/oracle-database/19/sqlrf/SELECT.html#GUID-CFA006CA-6FF1-4972-821E-6996142A51C6__BABBADDD

			Library goqu have OrderWithOffsetFetchSQL() special for strange dialects, like oracle.
			But this function don`t work if offset = 0 it skips offset+fetch part, but oracle don`t have LIMIT)
			https://github.com/doug-martin/goqu/blame/21b6e6d1cb1befe839044764d8ad6b1c6f0b5ef4/sqlgen/common_sql_generator.go#L116
	*/
	query = query +
		fmt.Sprintf(" OFFSET %s%d ROWS", string(PlaceHolderFragment), len(args)+1) +
		fmt.Sprintf(" FETCH NEXT %s%d ROWS ONLY", string(PlaceHolderFragment), len(args)+2)

	return query, append(args, offset, limit)
}

What about:

  1. Make Limit()/Offset() can take []any argument, not only uint, to use like this .Fetch(goqu.L(“? ROWS ONLY“, limit))
    or
  2. Delete this if

p.s. Yes, I know that oracle is PITA, and I must look for PG f.e., and Yes, I know about dirty oracle hack like this: https://stackoverflow.com/a/241643, but I don`t want to do it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant