Skip to content

ReadFile broken on DuckDB #522

@MikeBeller

Description

@MikeBeller

Hi! I'm new to Logica. Looking to use datalog for some AI-related work I am doing right now. Logica is a really intriguing project! Thanks for making it available.

I believe there is a bug in the duckdb implementation of ReadFile:

 logica - run Inp <<<'Inp() = ReadFile("input.txt");'
Traceback (most recent call last):
  File "/Users/mike/tmp/logi/.venv/bin/logica", line 10, in <module>
    sys.exit(run_main())
             ~~~~~~~~^^
  File "/Users/mike/tmp/logi/.venv/lib/python3.13/site-packages/logica/logica.py", line 345, in run_main
    main(sys.argv)
    ~~~~^^^^^^^^^^
  File "/Users/mike/tmp/logi/.venv/lib/python3.13/site-packages/logica/logica.py", line 290, in main
    cur = connection.sql(formatted_sql)
_duckdb.CatalogException: Catalog Error: Scalar Function with name pg_read_file does not exist!
Did you mean "pg_has_role"?

The implementation, in https://github.com/EvgSkv/logica/blob/0ce1da4576c1bbaa524c8b0daf5a98ee7b3bd766/compiler/dialect_libraries/duckdb_library.py#L50 seems to have been copied from the PostgreSQL implementation. Duckdb does not have a pg_read_file function, but it does have a read_text function. I tried just swapping the functions in the duckdb_library.py source, butread_text is a table function in duckdb, so that just produces a different error.:

_duckdb.BinderException: Binder Error: Function "read_text" is a table function but it was used as a scalar function. This function has to be called in a FROM clause (similar to a table).

As yet, I don't understand logica well enough to understand what the fix is, but I'm guessing its pretty simple.

Regards
Mike Beller

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions