1

I know that, there is no support for sequences in MySql. We can use Auto increment column for that. But in my scenario, in our application we gives user privilege to create sequence in database which is used for sequencing the file list on disk.

For example, following configuration will create files as shown:

<character-renaming-operation>        
    <query>select lpad(SEQ_FILENO.nextval,5, '0') from dual</query>
</character-renaming-operation>

This will create my files on disc as per following [considering seq start from 1].

output_file_00001.csv 
output_file_00002.csv 
output_file_00003.csv 
...

We cannot use any Java logic for this global sequence, as we have multiple JVM running for single Database. So how I can achieve same with single query in mysql?

Chintan Patel
  • 729
  • 3
  • 14
  • 31
  • I also need same kind of thing. With prefix as a present date. – Prashanth Debbadwar Apr 18 '17 at 07:40
  • it's not clear how your app works, does the file get uploaded to server or stored on clients PC? why not use the PK from `files` table if exist to produce the file name? ex, "output_file_0000"+PK+".csv", you can make the process as follow, when adding new file, first insert empty record in `files` table, and with the generated (auto-inc) PK create file name and update same record? – Yazan Apr 18 '17 at 07:46
  • Our application works with thousands of files within a day. We need to collect those files from remote server, process them and distribute them to another server bases on need of downstream. So we create daily/hourly bases partitions and etc. But within partition we need sequencing on demand. So we cannot hardcode it. Client can add any sequence as per his need. – Chintan Patel Apr 18 '17 at 07:54

0 Answers0