Primeiro suas strings estavam delimitadas por aspas duplas, quando o
postgres trabalhas com aspas simples para Strings em Query
Segundo, não estava escapando as aspas simples, que "cortavam" a string
pela metade, dando erro após o fim da String :
Message: 1
Date: Mon, 20 Mar 2006 22:24:52 -0300
From: Mauro Matos
<
[EMAIL PROTECTED]>
Subject:
Re: [PostgreSQL-Brasil] CROSSTAB FUNCTION
To:
[EMAIL PROTECTED],
[email protected]Message-ID:
<
[EMAIL PROTECTED]>
Content-Type:
text/plain; charset="iso-8859-1"
Paulo Rogerio Zimolo escreveu:
>
Amigos, bom dia!
> Estou com um problema na funcao abaixo, pois sempre
que executo recebo
> o seguinte erro:
> *ERROR: syntax
error at or near "S" at character 288*
> Sei que o erro refere-se ao
apostrofo no titulo da coluna (TEU'S), mas
> nao sei como fazer para
resolver.
> Alguem pode me ajudar?
> Sds
>
Paulo
>
>
> SELECT * FROM crosstab
(
> 'select year, fk_carrier, fk_direction, volume, sum(quantity)
from
> tbl_sindapar
> where year = '' 2005 '' and
fk_direction = '' Export ''
> group by year, 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
("year" int4, carrier text, sentido text, "TEU'S" int4, "FEU'S"
>
int4);
>
------------------------------------------------------------------------
>
>
_______________________________________________
> Grupo de Usuários do
PostgreSQL no Brasil
>
http://www.postgresql.org.brVeja
se ajuda. Um exemplo de consulta no terminal interativo psql:
teste1=#
insert into contatos (nome,email,endereco) values ('WHAT\'S
YOUR
NAME','[EMAIL PROTECTED]','RUA X, 9999');
INSERT 0 1
teste1=#
SELECT * FROM CONTATOS WHERE NOME LIKE 'WHAT\'S%';
id
| nome
|
email |
endereco
----+------------------+----------------------+-------------
8 | WHAT'S YOUR NAME |
[EMAIL PROTECTED] | RUA X,
9999
(1 registro)
-------------- Próxima Parte ----------
Um
anexo não texto foi limpo...
Nome : mauromatos.vcf
Tipo :
text/x-vcard
Tam : 117 bytes
Descr.: não
disponível
Url :
http://pgfoundry.org/pipermail/brasil-usuarios/attachments/20060321/f8d14e1f/attachment-0001.vcf
------------------------------
Message: 2
Date: Tue, 21 Mar
2006 08:31:27 -0300
From: "Salvador S. Scardua" <
[EMAIL PROTECTED]>
Subject:
Re: [PostgreSQL-Brasil] CROSSTAB FUNCTION
To: <
[email protected]>
Message-ID:
<
[EMAIL PROTECTED]>
Content-Type:
text/plain; charset="iso-8859-1"
Erro meu!
meu desculpe, esqueci de
corrigir as aspas que guardam toda string, tente assim:
where volume =
'TEU''S' or volume= "FEU''S'
Um abraço.
>Message:
5
>Date: Mon, 20 Mar 2006 11:41:10 -0300
>From: "Paulo Rogerio
Zimolo" <
[EMAIL PROTECTED]>
>Subject:
[PostgreSQL-Brasil] RES: CROSSTAB FUNCTION
>To: <
[email protected]>
>Message-ID:
>[EMAIL PROTECTED]>
>Content-Type:
text/plain; charset="iso-8859-1"
>Salvador, obrigado pela
ajuda.
>Fiz como sugerido e esta retornando o
seguinte:
>ERROR: column "TEU'S" does not
exist
>CONTEXT: SQL statement "select distinct volume from
tbl_sindapar
>where volume = "TEU'S" or volume =
"FEU'S"
>order by 1"
>Alguma
ideia?
>sds
>Paulo
> -----Mensagem original-----
>De:
[EMAIL PROTECTED]>[mailto:[EMAIL PROTECTED]
nome de Salvador S. Scardua
> Enviada em: segunda-feira, 20 de março de
2006 10:51
>Para: Lista PostgreSQL - Brasil
> Assunto: Re:
[PostgreSQL-Brasil] CROSSTAB FUNCTION
> Verifique esta
parte:
> where volume = "TEU'S" or volume=
"FEU'S"
> Muito provavelmente você precisará "escapar" o
caractere ' (aspas
>simples), para que a Query funcione.
> Faça um
teste duplicando o caractere aspas simples, o tornando
assim,
>escapado.
> where volume = "TEU''S" or
volume= "FEU ' 'S"
-------------- Próxima Parte ----------
Um
anexo em HTML foi limpo...
URL:
http://pgfoundry.org/pipermail/brasil-usuarios/attachments/20060321/0877fd7d/attachment-0001.html