3

I have been trying to learn SQL by doing the exercises on the Learn SQL the Hard Way site. I have made a file in folder on my desktop called ex1.sql, and I have put all of the sqlite3 stuff in PATH. However, I am using Windows Powershell and I cannot perform the command:

sqlite3 ex1.db < ex1.sql

I am getting this error in the Powershell terminal:

At line:1 char:16
+ sqlite3 ex1.db < ex1.sql
+                ~
The '<' operator is reserved for future use.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : RedirectionNotSupport

So, I guess '<' can only be used to redirect on Unix OS. I have tried to find an equivalent command in powershell, but I have not found one yet. If anyone has had this problem or knows how to redirect .sql files to .db, then that would be great.

2 Answers2

4

You could try:

get-content ext1.sql | sqllite3 ext1.db

The article has a nice discussion of legacy redirection issues in Powershell and various workarounds:

http://blogs.technet.com/b/heyscriptingguy/archive/2011/07/16/working-around-legacy-redirection-issues-with-powershell.aspx

Chad Miller
  • 40,127
  • 3
  • 30
  • 34
2

I came across this issue following along with Zed Shaw's Learn SQL the Hard Way on Powershell. The command he uses on Unix is

sqlite3 ex1.db < ex1.sql

Chad's answer works perfectly for Powershell. Zed is using the '<' redirection to read the CREATE statement from the .sql file and use that is input to the .db file.

In this Powershell example, Chad is reading the content of the .sql file and "piping" it into the .db file.

you can also type

gc ex1.sql | sqlite3 ex1.db

I hope this helps anybody that stumbles across this post while following along with Zed, like me! Thanks Zed and Chad!

HoppyKamper
  • 1,044
  • 9
  • 10