2
Server [localhost]:
Database [postgres]:
Port [5432]:
Username [postgres]:
Password for user postgres:
psql (10.6)
WARNING: Console code page (437) differs from Windows code page (1252)
     8-bit characters might not work correctly. See psql reference
     page "Notes for Windows users" for details.
Type "help" for help.



postgres=#  create database mydb;
CREATE DATABASE
postgres=#  psql -d mydb -f Telnet.sql;
ERROR:  syntax error at or near "psql"
LINE 1: psql -d mydb -f Telnet.sql;
    ^postgres=#

/*I am not able to figure out the error I have tried a number of other commands as well but I am not able to figure out the issue.

2
  • 2
    Possible duplicate of How do I run an SQL file in PostgreSQL using a Linux terminal? Commented Nov 11, 2018 at 4:29
  • You are trying to run the psql command line while already being connected to the database through psql. You have to come out (run \q)and execute that command from your host machine's command prompt. Commented Nov 11, 2018 at 4:56

1 Answer 1

8

You are already running psql so you can only execute SQL commands or psql specific commands

To connect to the newly created database use the psql command \c:

postgres=# \c mydb

The prompt should then change to

mydb=#

To run a SQL script from within psql use the psql command \i

mydb=# \i Telnet.sql

Note that psql commands (those starting with \) are not terminated with ; - that is only necessary for SQL commands.

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

1 Comment

You are now connected to database "mydb" as user "postgres". mydb=# \i Telnet.sql; Telnet.sql: No such file or directory mydb=#

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.