简体   繁体   中英

import .sql file into postgres using psql

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM