Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

import .sql file into postgres using psql

Tags:

postgresql

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.

like image 392
Praloy Choudhury Avatar asked Nov 18 '25 02:11

Praloy Choudhury


1 Answers

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.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!