I am new to SQLite and I have been trying to create a table in a database by importing a .csv file.
I type in the following commands:
sqlite>.mode csv
sqlite> .import testdata.csv testtable
No table is created and it returns the following line:
Usage: .import FILE TABLE
My machine is running Windows 10 and I have SQLite version 3.21
Quote the file name:
sqlite> .import "testdata.csv" testtable
Related
Currently I can use DB Browser for SQLite to open an encrypted DB file with password on Mac.
The options as per image:
Raw key (start with 0x...)
SQLCipher 3 defaults
I would like to open this file using command line instead of DB Browser.
Tried follow commands but seems no luck so far.
sqlcipher xxx.db
SQLite version 3.37.2 2022-01-06 13:25:41 (SQLCipher 4.5.1 community)
Enter ".help" for usage hints.
sqlite> pragma key="0xMyKey";
ok
sqlite> .tables
Error: file is not a database
Appreciate the help in advance so that I can use command line to access or export sqlite db just like mysql (mysql -u ... & mysqldump).
Found the documentation via this link: https://www.zetetic.net/sqlcipher/sqlcipher-api/
sqlcipher xxx.db
SQLite version 3.37.2 2022-01-06 13:25:41 (SQLCipher 4.5.1 community)
Enter ".help" for usage hints.
sqlite> PRAGMA key = "x'{KEY_WITHOUT_0X}'"; // Replace {KEY_WITHOUT_0X} with your key without 0x!
ok
sqlite> PRAGMA cipher_page_size = 1024;
sqlite> PRAGMA kdf_iter = 64000;
sqlite> PRAGMA cipher_hmac_algorithm = HMAC_SHA1;
sqlite> PRAGMA cipher_kdf_algorithm = PBKDF2_HMAC_SHA1;
sqlite> PRAGMA cipher_default_plaintext_header_size = 0;
sqlite>
I am new to sqlite. I want to inspect existing read only database like below.
$ ll /nix/var/nix/db/db.sqlite
-rw-r--r-- 1 root root 30445568 Jan 9 15:41 /nix/var/nix/db/db.sqlite
$ sqlite3 /nix/var/nix/db/db.sqlite
SQLite version 3.35.5 2021-04-19 18:32:05
Enter ".help" for usage hints.
sqlite> .databases
Error: attempt to write a readonly database
I don't get it. Do I need write access to simply query sqlite database? I need a few poiters here
I read in https://sqlite.org/wal.html about immutable query parameter. If I replace path with URI with that query parameter, then I can inspect the read-only database.
sqlite3 file:///nix/var/nix/db/db.sqlite?immutable=1
SQLite version 3.35.5 2021-04-19 18:32:05
Enter ".help" for usage hints.
sqlite> .databases
main: /nix/var/nix/db/db.sqlite r/o
sqlite> .tables
DerivationOutputs Refs ValidPaths
For example in DB2 there is a "user" that will give you who is logged in and performing the queries. And no, there is no "logging into DB2" I only login once to gain access to the whole OS (IBM i 7.1).
declare global temporary table XYZ ( DUMMY char(1))
Table XYZ created in QTEMP.
insert into XYZ values('1')
1 rows inserted in XYZ in QTEMP.
select user from XYZ
Output:
....+....1....+...
USER
"my-login-user-id-is-shown-here"
******** End of data ********
in sqlite3:
SQLite version 3.11.1 2016-03-03 16:17:53
Enter ".help" for usage hints.
sqlite> create temporary table XYZ (DUMMY char(1));
sqlite> insert into XYZ values('1')
...> ;
sqlite> select user from XYZ;
Error: no such column: user
sqlite>
Thanks in advance!
SQLite is a file-based database; it neither cares nor knows about OS users.
I tried this (running sqlite from the unix shell) and found it to be an acceptable solution, but I will like to be able to do the same from within the sqlite command shell.
% sqlite3 test.db "select * from NADA where UZER='$USER';"
-- Loading resources from /home/<my-userid>/.sqliterc
UZER DINERO
---------- ----------
<my-userid> 117.41
i have a csv file in hadoop and i have a Hive table ,now i want to laoad that csv file into this Hive table
i have used load LOAD DATA local 'path/to/csv/file' overwrite INTO TABLE tablename;
ended up with this error :
Error in .verify.JDBC.result(r, "Unable to retrieve JDBC result set for ", :
Unable to retrieve JDBC result set for LOAD DATA local
'path/to/csv/file' overwrite INTO TABLE tablename
(Error while processing statement: FAILED:
ParseException line 1:16 missing INPATH at ''path/tp csv/file'' near '<EOF>'
)
Note: i am trying this using RJDBC connection in r
I think the command to load CSV to Hive table is ( when CSV is in HDFS).
LOAD DATA INPATH '/user/test/my.csv' INTO TABLE my_test;
As your file is already present in the HDFS remove the keyword Local
LOAD DATA inpath 'path/to/csv/file' overwrite INTO TABLE tablename;
I have developed a tool to generate hive scripts from a csv file. Following are few examples on how files are generated.
Tool -- https://sourceforge.net/projects/csvtohive/?source=directory
Select a CSV file using Browse and set hadoop root directory ex: /user/bigdataproject/
Tool Generates Hadoop script with all csv files and following is a sample of
generated Hadoop script to insert csv into Hadoop
#!/bin/bash -v
hadoop fs -put ./AllstarFull.csv /user/bigdataproject/AllstarFull.csv
hive -f ./AllstarFull.hive
hadoop fs -put ./Appearances.csv /user/bigdataproject/Appearances.csv
hive -f ./Appearances.hive
hadoop fs -put ./AwardsManagers.csv /user/bigdataproject/AwardsManagers.csv
hive -f ./AwardsManagers.hive
Sample of generated Hive scripts
CREATE DATABASE IF NOT EXISTS lahman;
USE lahman;
CREATE TABLE AllstarFull (playerID string,yearID string,gameNum string,gameID string,teamID string,lgID string,GP string,startingPos string) row format delimited fields terminated by ',' stored as textfile;
LOAD DATA INPATH '/user/bigdataproject/AllstarFull.csv' OVERWRITE INTO TABLE AllstarFull;
SELECT * FROM AllstarFull;
Thanks
Vijay
I know this is the stupid question but i am so confused so please help me.
The question is when i use sqlite command line and make a database.
SQLite version 3.6.22
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> sqlite3 mydata.db
---> (now i terminate it using ;)
And now i craete tables and use .output filename and then select * from tb(table)
The file craeted nowhere!!
So please let me know where file craeted.
Or any other method to craete sqlite database file.
Thanks in advance.
What's wrong with this? It perfectly works and both mydatabase.db and foo_contents.txt exist.
C:\Users\··\Desktop>sqlite mydatabase.db
SQLite version 3.7.6.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo(bar text);
sqlite> begin transaction; insert into foo(bar) select 'a' union all select 'b';
sqlite> end transaction;
sqlite> .output '.\foo_contents.txt'
sqlite> select * from foo;
sqlite> .output stdout
sqlite> .q
C:\Users\··\Desktop>
Not sure about your trouble...
fpuga#ELNATH:/tmp$ sqlite3 database.sqlite
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .databases
seq name file
--- --------------- ----------------------------------------------------------
0 main /tmp/database.sqlite
sqlite> .exit
fpuga#ELNATH:/tmp$ ls *.sqlite
database.sqlite