ERROR: COPY delimiter must be a single one-byte character

后端 未结 5 1870
日久生厌
日久生厌 2020-12-16 17:24

I want to load the data from a flat file with delimiter \"~,~\" into a PostgreSQL table. I have tried it as below but looks like there is a restriction for the delimiter. If

5条回答
  •  佛祖请我去吃肉
    2020-12-16 17:50

    Unfortunatelly there is no way to load flat file with multiple characters delimiter ~,~ in Postgres unless you want to modify source code (and recompile of course) by yourself in some (terrific) way:

    /* Only single-byte delimiter strings are supported. */
    if (strlen(cstate->delim) != 1)
        ereport(ERROR,
            (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
        errmsg("COPY delimiter must be a single one-byte character")));
    

    What you want is to preprocess your input file with some external tool, for example sed might to be best companion on GNU/Linux platfom, for example:

    sed s/~,~/\\t/g inputFile
    

提交回复
热议问题