Syntax Error in Boolean Null values



  • I have a csv that contains Boolean variables (yes,no,blanks). How can I recode blanks so that it'd integrate in the data type. Or fo i have to change data type for blanks to be readable?


  • QA Engineer

    You can change how COPY represents NULL values.

    For example, assuming the following table:

    CREATE TABLE hasbool (
       id integer PRIMARY KEY,
       is_cool boolean,
       name text NOT NULL
    );
    

    I can use blanks to represent NULL as in the following psql session:

    \pset null '∅'
    Null display is "∅".
    

    COPY hasbool FROM STDIN (FORMAT 'csv', NULL ' ');
    Enter data to be copied followed by a newline.
    End with a backslash and a period on a line by itself, or an EOF signal.

    1,TRUE,joe
    2, ,paul
    .
    COPY 2

    TABLE hasbool;

    id │ is_cool │ name
    ════╪═════════╪══════
    1 │ t │ joe
    2 │ ∅ │ paul
    (2 rows)



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2