I have to upload a Unicode text file(want to show Japanese characters etc.) Into a netezza table. I have created a table with nvarchar columns and
I have given the below code but it doesn't work.
cat *filename.csv|nzconvert -f utf8 -t nfc|tr -d '\r' |nzload ......
any other options?
Here is an example of using nzload to load Unicode data into Netezza
[nz#netezza ~]$ cat test.txt
アイウエオカキクケコサシスセソタチツテ
[nz#netezza ~]$ nzsql -d testdb -c "create table nvarchar_test (col1 nvarchar(500))";
CREATE TABLE
[nz#netezza ~]$ nzload -db testdb -t nvarchar_test -df test.txt -ctrlchars
Load session of table 'NVARCHAR_TEST' completed successfully
[nz#netezza ~]$ nzsql -d testdb -c "select * from nvarchar_test"
COL1
---------------------
アイウエオカキクケコサシスセソタチツテ
(1 row)
Related
I am exporting sql view using .bat script:
sqlcmd -U HPH_COM -P HPH_COM -S vTF-DB\LEVEL2 -d HPH_COM -Q " SELECT TOP (1000) * FROM HPH_COM.dbo.REP_TEMP_STOCKS_LASTDAY " -o "C:\sajtovi\TF1_PyroMeasuresLastDay.csv"
And its working. However, exported csv file is not organized as when you export using SSMS: using batch one column in sql is not copied to one column in excel, but more columns from sql to one column in excel. so i cannot play with exported data. Any idea how to write script which will give same results as exported with ssms?
Thanks
you can use these options.
-h rows_per_header
-s col_separator
-W (remove trailing spaces)
and also specify set nocount on to prevent the completion message from appearing.
It looks like this.
sqlcmd -U HPH_COM -P HPH_COM -S vTF-DB\LEVEL2 -d HPH_COM -Q "set nocount on; SELECT TOP (1000) * FROM HPH_COM.dbo.REP_TEMP_STOCKS_LASTDAY " -o "C:\sajtovi\TF1_PyroMeasuresLastDay.csv" -W -h -1 -s,
BCP insert script is not restoring the Identity column values copied in the BCP file, instead SQL Server automatically assigns unique values based on the seed and increment values specified during the restoring process.
BCP format file creation -
BCP [SourceDatabase].[abc].[TableName] format nul -T -c -f Filename.fmt -S SourceSqlServer
BCP Data file creation -
BCP "EXEC [abc].[GetData]" queryout "C:\Filename.bcp" -S SourceSqlServer -d SourceDatabase -T **-E** -c
Restore data into the table -
BCP [abc].[TableName] in "C:\Filename.bcp" -f Filename.fmt -S SourceSqlServer -d SourceDatabase -T
I want to insert the values of the Identity column same as in the BCP file. Any suggestions appreciated.
You will need to add the -E switch by default bcp assigns new identity columns.
https://learn.microsoft.com/sr-latn-rs/sql/relational-databases/import-export/keep-identity-values-when-bulk-importing-data-sql-server?view=sql-server-2014
I am trying to create a windows batch file to export data from an SQL table to a .txt file with <~> as field separator.
I tried to escape with ^ still i am unable to export with <~> as field separator, below is the command
sqlcmd -S YourDBServer -d DB_NAME -E -Q "select mcc_code, 1, name, address, domain, mask from table" -o "tableName_date.txt" -s"^<~^>" -W -h -
how should i escape? Please help.
I use sqlcmd to execute large sql file which insert multiple of records into database. So when sqlcmd run it display a error message like "syntax error near 'Ed'..." . I known Ed is sql commands and i found -X will disable that kind of commands but it is not work.
My command like this:
sqlcmd -S "tcp:ip,1433" -U "sa" -P "pass" -d "dbname" -c "GO" -k 1 -f 65001 -i "C:\sql.sql" -X -x
My sql file content:
Go
insert into tablename (title) values (N'title
Ed some more data
some more data
some more data')
Go
insert into tablename (title) values (N'title
Ed some more data
some more data
some more data')
Go
Could you give me some help? please.
Thanks you.
It use -X[1] instead of -X.
sqlcmd -S "tcp:ip,1433" -U "sa" -P "pass" -d "dbname" -c "GO" -k 1 -f 65001 -i "C:\sql.sql" -X[1]
I need to execute postgresql queries from command line using psql -c command.
For every psql command, it opens a new tcp connection to connect to the database server and execute query which is a overhead for large number of queries.
Currently I can execute single query like this:
psql -U postgres -h <ip_addr> -c "SELECT * FROM xyz_table;"
When I tried to execute multiple queries as below, but only the last query got executed.
psql -U postgres -h <ip_addr> -c "SELECT * FROM xyz_table; SELECT * FROM abc_table;"
Can anyone help me and tell me the proper way to do it?
-c processes only one command. Without it however psql expects commands to be passed into standard input, e.g.:
psql -U postgres -h <ip_addr> <database_name> << EOF
SELECT * FROM xyz_table;
SELECT * FROM abc_table;
EOF
Or by using echo and pipes.
at least from 9.6.2 this approach works as well:
psql -c "select now()" -c "select version()" -U postgres -h 127.0.0.1
now
2017-12-26 20:25:45.874935+01
(1 row)
version
PostgreSQL 9.6.2 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.3.1-14ubuntu2) 5.3.1 20160413, 64-bit
(1 row)
Using echo and a pipe to fit it on a single line:
echo 'SELECT * FROM xyz_table; \n SELECT * FROM abc_table' | psql -U postgres
The --file parameter executes a file's content
psql -U postgres -h <ip_addr> -f "my_file.psql"
All the output will be sent to standard output
http://www.postgresql.org/docs/current/static/app-psql.html