Paulo Rogerio Zimolo escreveu:
Prezados Salvador e Mauro, bom dia!
Obrigado pela ajuda.
Refiz a funcao como sugerido (usando apenas aspas simples - vide abaixo), entretanto, continuo recebendo seguinte mensagem de erro (mesmo se usar a contra-barra no lugar de aspas)
Ja tentei de varias maneiras:
where volume = 'TEU''S' or volume= 'FEU''S'
where volume = ''TEU\'S'' or volume= ''FEU\'S''/
mas nenhuma delas parece funcionar na funcao CROSSTAB
sDS
Paulo
===============
ERROR:  syntax error at or near "S" at character 63
QUERY:  select distinct volume from tbl_sindapar
 where volume = 'TEU'S' or volume= 'FEU'S'
order by 1
=======================
SELECT * FROM crosstab (
 'select fk_carrier, fk_direction, volume, sum(quantity) from tbl_sindapar
 where fk_direction = ''Export''
 group by fk_carrier, fk_direction, volume
 order by 1',
'select distinct volume from tbl_sindapar
 where volume = ''TEU''S'' or volume= ''FEU''S''
order by 1') AS (carrier text, sentido text, TEUS int4, FEUS int4);
Veja os arquivos:

/usr/share/doc/postgresql-contrib-8.1.2/README.tablefunc
/usr/share/pgsql/contrib/tablefunc.sql

Use:
WHERE volume = ''TEUS''''S'' OR volume = ''FEU''S''
Porque se trata de um string dentro de uma outra string. :)

Exemplo:
teste1=# create table ct(id serial, rowclass text, rowid text, attribute text, value text);

teste1=# INSERT INTO CT(rowclass, rowid, attribute, value) VALUES('grupo1','teste1','name\'s','McDonald\'s');
INSERT 0 1
teste1=# INSERT INTO CT(rowclass, rowid, attribute, value) VALUES('grupo2','teste1','name\'s','Car\'s');
INSERT 0 1

teste1=# select * from ct where rowclass='grupo1';
id | rowclass | rowid  | attribute |   value
----+----------+--------+-----------+------------
 1 | grupo1   | teste1 | name's    | McDonald's
 2 | grupo1   | teste1 | name's    | Car's
(2 registros)

teste1=# SELECT * FROM crosstab('SELECT rowid, attribute, value FROM ct WHERE rowclass = ''grupo1'' AND attribute = ''name''''s'' ORDER BY value;') AS ct(row_name text, category_1 text, category_2 text);
row_name | category_1 | category_2
----------+------------+------------
teste1   | Car's      | McDonald's
(1 registro)


T+

begin:vcard
fn:Mauro Matos
n:Matos;Mauro
adr:;;;;;;Brasil
email;internet:[EMAIL PROTECTED]
version:2.1
end:vcard

_______________________________________________
Grupo de Usuários do PostgreSQL no Brasil
http://www.postgresql.org.br

Responder a