Importing .sql file on windows to postgresql
You should use psql command line tool:
psql -h hostname -p port_number -U username -f your_file.sql databasename
Import SQL dump into PostgreSQL database
psql databasename < data_base_dump
That's the command you are looking for.
Beware: databasename
must be created before importing.
Have a look at the PostgreSQL Docs Chapter 23. Backup and Restore.
Not able to import sql file onto PostgreSql in windows
Either
psql.exe -U postgres -d development < "d:\myprojects\ruby\HelloWorld\db\data.sql"
or
psql.exe -U postgres -d development -f "d:\myprojects\ruby\HelloWorld\db\data.sql"
How do I import a file of SQL commands to PostgreSQL?
Okay, the problem does have to do with BOM, byte order marker. The file was generated by Microsoft Access. I opened the file in Notepad and saved it as UTF-8 instead of Unicode since Windows saves UTF-16 by default. That got this error message:psql:filenameincurrentdirectory.sql:1: ERROR: syntax error at or near "INSERT"
LINE 1: INSERT INTO general_lookups ("name", "old_id" ) VAL...
I then learned from another website that Postgres doesn't utilize the BOM and that Notepad doesn't allow users to save without a BOM. So I had to download Notepad++, set the encoding to UTF-8 without BOM, save the file, and then import it. Voila!
An alternative to using Notepad++ is this little python script I wrote. Simply pass in the file name to convert.
import sys
if len(sys.argv) == 2:
with open(sys.argv[1], 'rb') as source_file:
contents = source_file.read()
with open(sys.argv[1], 'wb') as dest_file:
dest_file.write(contents.decode('utf-16').encode('utf-8'))
else:
print "Please pass in a single file name to convert."
How to import SQL dump into Postgres DB running on Vagrant instance of Ubuntu
So given an sql dump file as dump.sql
.
- Run
vagrant ssh
on an ssh client like git bash(for windows) - Put the dump file in the directory containing the vagrantfile on the host machine. As it syncs by default with the guest machine or run
vagrant rsync
, just to make sure. - Navigate to the vagrant directory on the host machine (eg
cd ../../
for an ubuntu guest on a window host) - Run
psql -h hostname -U test -d databasename -f dump.sql
.
How to import existing *.sql files in PostgreSQL 8.4?
in command line first reach the directory where psql is present then write commands like this:
psql [database name] [username]
and then press enter psql asks for password give the user password:
then write
> \i [full path and file name with extension]
then press enter insertion done.
Related Topics
Full-Text Search SQL Server 2005
SQL Missing Right Parenthesis on Order by Statement
Total Children Values Based on Parent
Query SQL to Subtract Two Fields
SQL Queries on String Columns - Sorting According to Language
Convert SQL Server Result Set into String
SQL Query Through an Intermediate Table
How to Pass a Parameter from Vb.Net
Tsql Left Join and Only Last Row from Right
Just Get Column Names from Hive Table
How to Get Rid of #Temp Tables from the Query
Divide the Table Data Randomly Based on Percentages
Difference Between Inner Join and Left Semi Join
Select Count of Rows in Another Table in a Postgres Select Statement
SQL Management Studio Won't Recognize a Table Exists After Scripted Create
Query the Two Cities in Station with the Shortest and Longest City Names,