0

I am trying to delete the first & last row with Java HyperAPI which i used to optimise big data into .hyper file. in tableau server. Im not sure if this possible but based on the documentation, some of the use cases i read , its possible

based on normal sql query , we can delete the first row with

delete top(1) from tablename 

Script shown below is working fine which is able to remove row based on where condition

            long rowCountDeletedInCustomersTable = connection.executeCommand(
                    "DELETE FROM " + escapeName("Customer") +
                            "WHERE " + escapeName("Customer Name") + "=" + escapeStringLiteral("Dennis Kane")
            ).getAsLong();

however when i tried to delete the first with

long rowCountDeletedInCustomersTable = connection.executeCommand(
DELETE TOP(1) from " + escapeName("Customer")).getAsLong()

or

long rowCountDeletedInCustomersTable = connection.executeCommand(
DELETE FROM table WHERE ROWNUM = 1).getAsLong()

this will throw error, im not sure on which approach should i use

Farid Arshad
  • 334
  • 2
  • 14

1 Answers1

0

I am not really sure why you want to delete the "first" or "last" row from a Hyper file. Note that Hyper has no notion of "row order", so which row is considered to be the first/last row is somewhat random...

Hyper's SQL syntax follows Postgres' conventions instead of Microsoft's SQL dialect. DELETE TOP(1) is a Microsoft-specific syntax.

Hyper doesn't have a corresponding syntax. But assuming you have a column your_row_id which forms a key for your relationship, you can use

DELETE FROM tablename
WHERE your_row_id IN (SELECT your_row_id FROM tablename LIMIT 1)
Vogelsgesang
  • 684
  • 1
  • 4
  • 15