prestodb/presto · error · RuntimeException

both --execute and --file specified

Error message

both --execute and --file specified

What it means

The Presto CLI allows supplying a query either via --execute or via --file, but not both. Console.run concatenates --execute values and, if --file was also given, throws to prevent ambiguity about which query to run.

Source

Thrown at presto-cli/src/main/java/com/facebook/presto/cli/Console.java:102

    {
        ClientSession session = clientOptions.toClientSession();
        boolean hasQuery = !isNullOrEmpty(clientOptions.execute);
        boolean isFromFile = !isNullOrEmpty(clientOptions.file);

        if (!hasQuery && !isFromFile) {
            AnsiConsole.systemInstall();
        }

        initializeLogging(clientOptions.logLevelsFile);

        String query = clientOptions.execute;
        if (hasQuery) {
            query += ";";
        }

        if (isFromFile) {
            if (hasQuery) {
                throw new RuntimeException("both --execute and --file specified");
            }
            try {
                query = Files.asCharSource(new File(clientOptions.file), UTF_8).read();
                hasQuery = true;
            }
            catch (IOException e) {
                throw new RuntimeException(format("Error reading from file %s: %s", clientOptions.file, e.getMessage()));
            }
        }

        // abort any running query if the CLI is terminated
        AtomicBoolean exiting = new AtomicBoolean();
        ThreadInterruptor interruptor = new ThreadInterruptor();
        CountDownLatch exited = new CountDownLatch(1);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            exiting.set(true);
            interruptor.interrupt();
            awaitUninterruptibly(exited, EXIT_DELAY.toMillis(), MILLISECONDS);

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use only one of --execute or --file
  2. Move the inline SQL into the file (or vice versa) and pass a single source
  3. If flags come from a wrapper script, conditionally add --execute only when no --file is present

Example fix

// before
presto --file queries/q.sql --execute "SELECT 1"
// after
presto --file queries/q.sql
Defensive patterns

Strategy: validation

Validate before calling

// shell guard before invoking the CLI
if [ -n "$PRESTO_EXECUTE" ] && [ -n "$PRESTO_FILE" ]; then
  echo "Use only one of --execute or --file" >&2; exit 1;
fi

Try / catch

try { runCli(args); } catch (RuntimeException e) { if (e.getMessage().contains("--execute and --file")) { /* strip one flag and retry */ } else throw e; }

Prevention

When it happens

Trigger: Running presto with both --execute "<sql>" and --file <path> on the command line.

Common situations: Wrapping scripts that append --execute to a command template that already passes --file; copy-pasted CLI invocations combining both flags.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/0692b82df8845076. Report an issue: GitHub.