codenotary / immudb

immudb - immutable database based on zero trust, SQL/Key-Value/Document model, tamperproof, data change history
https://immudb.io
Other
8.55k stars 343 forks source link

Execute a SQL file #2008

Closed sleepycat closed 3 weeks ago

sleepycat commented 1 month ago

What would you like to be added or enhanced

It would be useful to be able to execute a .sql file like you can with psql:

psql --set='sslmode=disable' -h localhost -d defaultdb -U immudb -p 5432 -f demo.sql.

Why is this needed This is a useful feature for quickly executing large numbers of SQL statements and is widely supported by most other databases.

Additional context

It seems that either the postgres compatibility should support this so the above psql command can work or some equivalent command could be added to immuclient. Ideally both!

ostafen commented 1 month ago

@sleepycat: sounds like the pgsql server is not able to recognize that SSL is disabled when using the --set='sslmode=disable' option. I will further explore why, but for now a quick fix is to run the following command instead:

psql "host=localhost user=immudb dbname=defaultdb password=immudb sslmode=disable" -p 5432 -f demo.sql

which works as expected.

EDIT: after further investigation, I found out that the --set option in psql is used to set variables for use within the SQL session. These variables can be referenced in SQL scripts using the :variable_name syntax. In other words, it does not influence how psql connects to the database. Setting sslmode this way will not disable SSL for the connection.

An alternative which also works is:

PGSSLMODE=disable psql -h localhost -d defaultdb -U immudb -p 5432 -f demo.sql
sleepycat commented 3 weeks ago

That works for me! Thanks.