1

I am running the sql script for postgres.

Sql script(books.sql) is:

CREATE TABLE tablename AS TABLE booksback WITH NO DATA;

INSERT INTO tablename (SELECT * from booksback);

TRUNCATE TABLE books CASCADE;

I want to set the table name with command line argument.

I am running the script as:

postgres=# \i \books.sql;

I want to know how to set the pass the table name in sql file using \i option in postgres.

I have tried the -v option and :set as well.

1 Answer 1

2

It's not possible because \i takes only one parameter: the filename to be processed.

If you want to pass additional parameters you need to use psql command line arguments that you mentioned like -v.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.