Bcp command into Microsoft Azure












1















I'm trying to use bcp command to append data into exist table in azure db.



When I'm exporting the csvtxt file directly from command line - it looks like a binary file, and then the import from this file pass fine.



But if I'm trying to take a python pandas dataframe which has the same data and save it as csvtxt, the content is different - there is no binary data - just the normal values.



But then, after the import from that file - there is no error but 0 rows imported...



How can I create csv from dataframe that will be the same as the bcp csv?



this is my working code (directly from command line):



--export
bcp "select * from tbl where val=1" queryout "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,

--import
bcp tbl2 in "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,


this is my python code:



import subprocess as sp
...
df0.to_csv('tm2.csv',encoding='utf8',index=None,sep=',',header=None)

cmd2='bcp tbl2 in "Testtm2.csv" -S <server> -d <db> -U <user> -P <password> -q -t, -n'

sp.call(cmd2)


but the table tbl2 with no change.










share|improve this question























  • Anybody? How can I generate the csv from pandas exatcly like it's generate from the bcp? what is the different?

    – user2671057
    Nov 22 '18 at 10:00
















1















I'm trying to use bcp command to append data into exist table in azure db.



When I'm exporting the csvtxt file directly from command line - it looks like a binary file, and then the import from this file pass fine.



But if I'm trying to take a python pandas dataframe which has the same data and save it as csvtxt, the content is different - there is no binary data - just the normal values.



But then, after the import from that file - there is no error but 0 rows imported...



How can I create csv from dataframe that will be the same as the bcp csv?



this is my working code (directly from command line):



--export
bcp "select * from tbl where val=1" queryout "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,

--import
bcp tbl2 in "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,


this is my python code:



import subprocess as sp
...
df0.to_csv('tm2.csv',encoding='utf8',index=None,sep=',',header=None)

cmd2='bcp tbl2 in "Testtm2.csv" -S <server> -d <db> -U <user> -P <password> -q -t, -n'

sp.call(cmd2)


but the table tbl2 with no change.










share|improve this question























  • Anybody? How can I generate the csv from pandas exatcly like it's generate from the bcp? what is the different?

    – user2671057
    Nov 22 '18 at 10:00














1












1








1








I'm trying to use bcp command to append data into exist table in azure db.



When I'm exporting the csvtxt file directly from command line - it looks like a binary file, and then the import from this file pass fine.



But if I'm trying to take a python pandas dataframe which has the same data and save it as csvtxt, the content is different - there is no binary data - just the normal values.



But then, after the import from that file - there is no error but 0 rows imported...



How can I create csv from dataframe that will be the same as the bcp csv?



this is my working code (directly from command line):



--export
bcp "select * from tbl where val=1" queryout "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,

--import
bcp tbl2 in "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,


this is my python code:



import subprocess as sp
...
df0.to_csv('tm2.csv',encoding='utf8',index=None,sep=',',header=None)

cmd2='bcp tbl2 in "Testtm2.csv" -S <server> -d <db> -U <user> -P <password> -q -t, -n'

sp.call(cmd2)


but the table tbl2 with no change.










share|improve this question














I'm trying to use bcp command to append data into exist table in azure db.



When I'm exporting the csvtxt file directly from command line - it looks like a binary file, and then the import from this file pass fine.



But if I'm trying to take a python pandas dataframe which has the same data and save it as csvtxt, the content is different - there is no binary data - just the normal values.



But then, after the import from that file - there is no error but 0 rows imported...



How can I create csv from dataframe that will be the same as the bcp csv?



this is my working code (directly from command line):



--export
bcp "select * from tbl where val=1" queryout "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,

--import
bcp tbl2 in "Testtbl1.csv" -S <server> -d <db> -U <user> -P <password> -q -n -t,


this is my python code:



import subprocess as sp
...
df0.to_csv('tm2.csv',encoding='utf8',index=None,sep=',',header=None)

cmd2='bcp tbl2 in "Testtm2.csv" -S <server> -d <db> -U <user> -P <password> -q -t, -n'

sp.call(cmd2)


but the table tbl2 with no change.







python pandas azure csv bcp






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 20:17









user2671057user2671057

564416




564416













  • Anybody? How can I generate the csv from pandas exatcly like it's generate from the bcp? what is the different?

    – user2671057
    Nov 22 '18 at 10:00



















  • Anybody? How can I generate the csv from pandas exatcly like it's generate from the bcp? what is the different?

    – user2671057
    Nov 22 '18 at 10:00

















Anybody? How can I generate the csv from pandas exatcly like it's generate from the bcp? what is the different?

– user2671057
Nov 22 '18 at 10:00





Anybody? How can I generate the csv from pandas exatcly like it's generate from the bcp? what is the different?

– user2671057
Nov 22 '18 at 10:00












1 Answer
1






active

oldest

votes


















0














There is an issue in your bcp command line. According to the offical document about bcp Utility, the -n option means to use the native (database) data types of the data, which exports data as a binary format, please see below.




-n Performs the bulk-copy operation using the native (database) data types of the data. This option does not prompt for each field; it uses
the native values.



For more information, see Use Native Format to Import or Export Data (SQL Server).




However, in your scenario, to import/export csv format data file must to use -c option, see the explaination below.




-c Performs the operation using a character data type. This option does not prompt for each field; it uses char as the storage type,
without prefixes and with t (tab character) as the field separator
and rn (newline character) as the row terminator. -c is not
compatible with -w.



For more information, see Use Character Format to Import or Export Data (SQL Server).




So if you want to import a csv data file exported from a pandas dataframe, the correct way is to use -c instead of -n, then it works for importing and exporting CSV format data file by bcp on SQL Database.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419871%2fbcp-command-into-microsoft-azure%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    There is an issue in your bcp command line. According to the offical document about bcp Utility, the -n option means to use the native (database) data types of the data, which exports data as a binary format, please see below.




    -n Performs the bulk-copy operation using the native (database) data types of the data. This option does not prompt for each field; it uses
    the native values.



    For more information, see Use Native Format to Import or Export Data (SQL Server).




    However, in your scenario, to import/export csv format data file must to use -c option, see the explaination below.




    -c Performs the operation using a character data type. This option does not prompt for each field; it uses char as the storage type,
    without prefixes and with t (tab character) as the field separator
    and rn (newline character) as the row terminator. -c is not
    compatible with -w.



    For more information, see Use Character Format to Import or Export Data (SQL Server).




    So if you want to import a csv data file exported from a pandas dataframe, the correct way is to use -c instead of -n, then it works for importing and exporting CSV format data file by bcp on SQL Database.






    share|improve this answer




























      0














      There is an issue in your bcp command line. According to the offical document about bcp Utility, the -n option means to use the native (database) data types of the data, which exports data as a binary format, please see below.




      -n Performs the bulk-copy operation using the native (database) data types of the data. This option does not prompt for each field; it uses
      the native values.



      For more information, see Use Native Format to Import or Export Data (SQL Server).




      However, in your scenario, to import/export csv format data file must to use -c option, see the explaination below.




      -c Performs the operation using a character data type. This option does not prompt for each field; it uses char as the storage type,
      without prefixes and with t (tab character) as the field separator
      and rn (newline character) as the row terminator. -c is not
      compatible with -w.



      For more information, see Use Character Format to Import or Export Data (SQL Server).




      So if you want to import a csv data file exported from a pandas dataframe, the correct way is to use -c instead of -n, then it works for importing and exporting CSV format data file by bcp on SQL Database.






      share|improve this answer


























        0












        0








        0







        There is an issue in your bcp command line. According to the offical document about bcp Utility, the -n option means to use the native (database) data types of the data, which exports data as a binary format, please see below.




        -n Performs the bulk-copy operation using the native (database) data types of the data. This option does not prompt for each field; it uses
        the native values.



        For more information, see Use Native Format to Import or Export Data (SQL Server).




        However, in your scenario, to import/export csv format data file must to use -c option, see the explaination below.




        -c Performs the operation using a character data type. This option does not prompt for each field; it uses char as the storage type,
        without prefixes and with t (tab character) as the field separator
        and rn (newline character) as the row terminator. -c is not
        compatible with -w.



        For more information, see Use Character Format to Import or Export Data (SQL Server).




        So if you want to import a csv data file exported from a pandas dataframe, the correct way is to use -c instead of -n, then it works for importing and exporting CSV format data file by bcp on SQL Database.






        share|improve this answer













        There is an issue in your bcp command line. According to the offical document about bcp Utility, the -n option means to use the native (database) data types of the data, which exports data as a binary format, please see below.




        -n Performs the bulk-copy operation using the native (database) data types of the data. This option does not prompt for each field; it uses
        the native values.



        For more information, see Use Native Format to Import or Export Data (SQL Server).




        However, in your scenario, to import/export csv format data file must to use -c option, see the explaination below.




        -c Performs the operation using a character data type. This option does not prompt for each field; it uses char as the storage type,
        without prefixes and with t (tab character) as the field separator
        and rn (newline character) as the row terminator. -c is not
        compatible with -w.



        For more information, see Use Character Format to Import or Export Data (SQL Server).




        So if you want to import a csv data file exported from a pandas dataframe, the correct way is to use -c instead of -n, then it works for importing and exporting CSV format data file by bcp on SQL Database.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 6:31









        Peter PanPeter Pan

        11.6k3823




        11.6k3823
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53419871%2fbcp-command-into-microsoft-azure%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            Npm cannot find a required file even through it is in the searched directory