ERROR: syntax error on or near «'postgresql

0

Hi, I have the following problem, I'm trying to create a view in postgresql

this is my instruction:

CREATE OR REPLACE VIEW cat_ejemplo_view AS 
 SELECT CCC.c_campo1 as id_campo1, CCC.c_campo2 as descripcion
   FROM dblink('host=pruebas dbname=baseprueba user=admin password=admin'::text,
               'select CCC.c_campo1, CCC.c_campo2 from  catalogo_tabla CCC 
                WHERE CCC.c_campo1 LIKE '%000000' AND CCC.c_campo2 != '' AND CCC.version = 3
                order by c_campo1 '::text)
    CCC(c_campo1 character varying(7), c_campo2 character varying(200))
  ORDER BY ccc.c_campo1;

When the execution marks me syntax error in the LIKE '% 000000 ' if I execute the query only if I recover the information the problem is to create a view with that query.

I'm using version 9.5

    
asked by SoftMolina 14.06.2017 в 00:33
source

2 answers

2

Finally I could solve it I also got the following error ERROR: unterminated quoted string at or near postgresql and this is why you have to put double apostrophe in the conditions ='''' which would be as follows:

CREATE OR REPLACE VIEW cat_ejemplo_view AS 
 SELECT CCC.c_campo1 as id_campo1, CCC.c_campo2 as descripcion
   FROM dblink('host=pruebas dbname=baseprueba user=admin password=admin'::text,
               'select CCC.c_campo1, CCC.c_campo2 from  catalogo_tabla CCC 
                WHERE CCC.c_campo1 LIKE ''%000000'' AND CCC.c_campo2 != '''' AND CCC.version = 3
                order by c_campo1 '::text)
    CCC(c_campo1 character varying(7), c_campo2 character varying(200))
  ORDER BY ccc.c_campo1;
    
answered by 14.06.2017 / 03:15
source
0

I think there is an apostrophe left over at the beginning of the fourth line, it would look like this:

CREATE OR REPLACE VIEW cat_ejemplo_view AS 
 SELECT CCC.c_campo1 as id_campo1, CCC.c_campo2 as descripcion
   FROM dblink('host=pruebas dbname=baseprueba user=admin password=admin'::text,
               select CCC.c_campo1, CCC.c_campo2 from  catalogo_tabla CCC 
               WHERE CCC.c_campo1 LIKE '%000000' AND CCC.c_campo2 != '' AND CCC.version = 3
               order by c_campo1 '::text)
    CCC(c_campo1 character varying(7), c_campo2 character varying(200))
  ORDER BY ccc.c_campo1;
    
answered by 14.06.2017 в 01:39