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

Enhance SCRIPT to support operations on STDOUT #3405

Closed
marcellorinaldo opened this issue Jan 27, 2022 · 3 comments · Fixed by #3409
Closed

Enhance SCRIPT to support operations on STDOUT #3405

marcellorinaldo opened this issue Jan 27, 2022 · 3 comments · Fixed by #3409

Comments

@marcellorinaldo
Copy link
Contributor

As now, the SCRIPT command is able to produce an output on file or in form of a ResultSet if no TO clause is specified.

Since the database can be large and disk space or heap memory can be limited, it would be useful to have the SCRIPT command output to stdout and RUNSCRIPT read from stdin so to avoid intermediate temporary files.

To achieve the result we tried using UNIX named pipes without success: the pipe is always replaced by a regular file. Note that the RunScript tool seems to be able to read from a named pipe.

@katzyn
Copy link
Contributor

katzyn commented Jan 27, 2022

SCRIPT and RUNSCRIPT commands are executed on the server side, server process normally doesn't have I/O streams. Hypothetically they can support them only in embedded databases, but from my point of view it's a bad idea to introduce a feature with this limitation.

Actually there are special files /dev/stdin, /dev/stdout, /dev/stderr on POSIX systems and con on Windows and there is no need to duplicate their functionality. The only problem is that SCRIPT tries to delete the target file, it needs a flag to append output to existing file instead.

@marcellorinaldo
Copy link
Contributor Author

SCRIPT and RUNSCRIPT commands are executed on the server side, server process normally doesn't have I/O streams. Hypothetically they can support them only in embedded databases, but from my point of view it's a bad idea to introduce a feature with this limitation.

I agree that on servers this functionality has no sense. However, on embedded environments where memory and disk space are scarce resources it would be nice to combine SCRIPT and RUNSCRIPT in pipe operations to avoid the creation of intermediate files. In this way it is possible to migrate a persisted database to the new version just using the command line tool without temporary files.

Actually there are special files /dev/stdin, /dev/stdout, /dev/stderr on POSIX systems and con on Windows and there is no need to duplicate their functionality. The only problem is that SCRIPT tries to delete the target file, it needs a flag to append output to existing file instead.

So, is it feasible to implement this special flag? Then, is it safe to import a database from a pipe using RUNSCRIPT?

@grandinj
Copy link
Contributor

There are already command line tools for doing RUNSCRIPT and SCRIPT

https://h2database.com/html/tutorial.html#command_line_tools

but they might need enhancement to work with pipes

@katzyn katzyn changed the title Enhance SCRIPT/RUNSCRIPT to support operations on STDIN/STDOUT Enhance SCRIPT to support operations on STDIN/STDOUT Jan 29, 2022
@katzyn katzyn changed the title Enhance SCRIPT to support operations on STDIN/STDOUT Enhance SCRIPT to support operations on STDOUT Jan 29, 2022
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

Successfully merging a pull request may close this issue.

3 participants