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 Answers 2

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

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

2 Comments

Thank you! I was unable to get it to work using the get-content method, but it did work when I used the old DOS command as explained in the article: CMD /c "sqlite3 ex1.db < ex1.sql"
It is sqlite3 not sqllite3
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!

Comments

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.