String literals and escape characters in postgresql

后端 未结 5 549
灰色年华
灰色年华 2020-11-28 07:55

Attempting to insert an escape character into a table results in a warning.

For example:

create table EscapeTest (text varchar(50));

insert into Es         


        
5条回答
  •  北海茫月
    2020-11-28 08:11

    I find it highly unlikely for Postgres to truncate your data on input - it either rejects it or stores it as is.

    milen@dev:~$ psql
    Welcome to psql 8.2.7, the PostgreSQL interactive terminal.
    
    Type:  \copyright for distribution terms
           \h for help with SQL commands
           \? for help with psql commands
           \g or terminate with semicolon to execute query
           \q to quit
    
    milen=> create table EscapeTest (text varchar(50));
    CREATE TABLE
    milen=> insert into EscapeTest (text) values ('This will be inserted \n This will not be');
    WARNING:  nonstandard use of escape in a string literal
    LINE 1: insert into EscapeTest (text) values ('This will be inserted...
                                                  ^
    HINT:  Use the escape string syntax for escapes, e.g., E'\r\n'.
    INSERT 0 1
    milen=> select * from EscapeTest;
              text
    ------------------------
     This will be inserted
      This will not be
    (1 row)
    
    milen=>
    

提交回复
热议问题