postgres dblink escape single quote

前端 未结 2 463
闹比i
闹比i 2020-12-20 13:53

Related Link:

  • String literals and escape characters in postgresql

Here is my error:

ERROR:  type \"e\" does not exist


        
相关标签:
2条回答
  • 2020-12-20 14:20

    Try replacing \'inactive\' with ''inactive'' -- caution: two single quotes

       SELECT *
        FROM dblink('host=theHostName port=1234 dbname=theDBName user=theUser password=thePassword',
            'SELECT field_1, 
            CASE WHEN field_2 IS NOT NULL 
            THEN ''inactive'' ELSE ''active'' 
            END AS field_status 
            FROM the_table 
             ') 
    
    AS linkresults(field_1 varchar(20),field_2 varchar(8))
    

    Alternative (previous) solution

       SELECT *
        FROM dblink('host=theHostName port=1234 dbname=theDBName user=theUser password=thePassword',
            'SELECT field_1, 
            CASE WHEN field_2 IS NOT NULL 
            THEN E\'inactive\' ELSE E\'active\' 
            END AS field_status 
            FROM the_table 
             ') 
    
    AS linkresults(field_1 varchar(20),field_2 varchar(8))
    
    0 讨论(0)
  • 2020-12-20 14:25

    Try this query:

    SELECT *
     FROM dblink('host=theHostName port=1234 dbname=theDBName user=theUser password=thePassword',
     'SELECT field_1, 
     CASE WHEN field_2 IS NOT NULL 
     THEN $$inactive$$ ELSE $$active$$ 
     END AS field_status 
     FROM the_table') 
     AS linkresults(field_1 varchar(20),field_2 varchar(8))
    
    0 讨论(0)
提交回复
热议问题