agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
FirebirdSQL to PostgreSQL
3+ messages / 3 participants
[nested] [flat]

* FirebirdSQL to PostgreSQL
@ 2017-09-12 11:31  =?iso-8859-9?B?RXJ0YW4gS/zn/Gtv8Gx1?= <ertan.kucukoglu@1nar.com.tr>
  0 siblings, 1 reply; 3+ messages in thread

From: Ertan Küçükoðlu @ 2017-09-12 11:31 UTC (permalink / raw)
  To: pgsql-sql

Hello,

I have below sql running fine on FirebirdSQL but not on PostgreSQL. As I am
not the editor of the SQL, I cannot fix it to work with PostgreSQL. Any help
is appreciated.

Not posting table details not to bloat the message.

I do not have Access to database right now. Error Message I receive is
something like:
Field "kaynak" not found on right table

SELECT 
  RAPOR_EK.KAYNAK, 
  RAPOR_EK.SEBEP, 
  COALESCE(DT.IAIK_OG, 0) AS "IAIK_OG",
  COALESCE(DT.IAIK_AG, 0) AS "IAIK_AG",
  COALESCE(DT.IAIK_TOPLAM, 0) AS "IAIK_TOPLAM",
  COALESCE(DT.IADK_OG, 0) AS "IADK_OG",
  COALESCE(DT.IADK_AG, 0) AS "IADK_AG",
  COALESCE(DT.IADK_TOPLAM, 0) AS "IADK_TOPLAM",
  COALESCE(DT.GNLTOPLAM, 0) AS "GNLTOPLAM"
FROM RAPOR_EK
LEFT JOIN (
  SELECT 
    M.TKS_KAYNAGAGORE AS "KAYNAK", 
    M.TKS_SEBEBEGORE AS "SEBEP", 
    (sum(M.TES_IMARALANICIOG)/(select sum(I.ILC_IMARALANICI_OG) from
ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IAIK_OG",
    (sum(M.TES_IMARALANICIAG)/(select sum(I.ILC_IMARALANICI_AG) from
ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IAIK_AG",
    ((sum(M.TES_IMARALANICIOG) + sum(M.TES_IMARALANICIAG)) / ((select
sum(I.ILC_IMARALANICI_OG) from ILCELER_TABLOSU I where I.ILCEADI =
'CÝHANBEYLÝ')  + (select sum(I.ILC_IMARALANICI_AG) from ILCELER_TABLOSU I
where I.ILCEADI = 'CÝHANBEYLÝ'))*60) AS "IAIK_TOPLAM",
    (sum(M.TES_IMARALANDISIOG)/(select sum(I.ILC_IMARALANDISI_OG) from
ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IADK_OG",
    (sum(M.TES_IMARALANDISIAG)/(select sum(I.ILC_IMARALANDISI_AG) from
ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IADK_AG",
    ((sum(M.TES_IMARALANDISIOG) + sum(M.TES_IMARALANDISIAG)) / ((select
sum(I.ILC_IMARALANDISI_OG) from ILCELER_TABLOSU I where I.ILCEADI =
'CÝHANBEYLÝ')  + (select sum(I.ILC_IMARALANDISI_AG) from ILCELER_TABLOSU I
where I.ILCEADI = 'CÝHANBEYLÝ'))*60) AS "IADK_TOPLAM",
    ((sum(M.TES_IMARALANICIOG) + sum(M.TES_IMARALANICIAG) +
(sum(M.TES_IMARALANDISIOG) + sum(M.TES_IMARALANDISIAG))) / ((select
sum(I.ILC_IMARALANICI_OG) from ILCELER_TABLOSU I where I.ILCEADI =
'CÝHANBEYLÝ')  + (select sum(I.ILC_IMARALANICI_AG) from ILCELER_TABLOSU I
where I.ILCEADI = 'CÝHANBEYLÝ') + (select sum(I.ILC_IMARALANDISI_OG) from
ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ') + (select
sum(I.ILC_IMARALANDISI_AG) from ILCELER_TABLOSU I where I.ILCEADI =
'CÝHANBEYLÝ'))*60) AS "GNLTOPLAM" 
  FROM TABLO_MEDAS M
  WHERE 
    M.T_ILCE = 'CÝHANBEYLÝ' 
    AND M.T_BILDIRIMEGORE = 'Bildirimsiz'
    AND M.TKS_SUREYEGORE = 'Uzun'
    AND (M.T_BASLAMATARIHI >= '2015-01-01' AND T_BASLAMATARIHI <=
'2015-01-31 23:59:59')
  GROUP BY 
    M.TKS_KAYNAGAGORE,
    M.TKS_SEBEBEGORE
) DT USING (KAYNAK, SEBEP)
ORDER BY KAYNAK, SEBEP







-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: FirebirdSQL to PostgreSQL
@ 2017-09-12 12:10  Tom Lane <tgl@sss.pgh.pa.us>
  parent: =?iso-8859-9?B?RXJ0YW4gS/zn/Gtv8Gx1?= <ertan.kucukoglu@1nar.com.tr>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2017-09-12 12:10 UTC (permalink / raw)
  To: Ertan Küçükoðlu <ertan.kucukoglu@1nar.com.tr>; +Cc: pgsql-sql

=?iso-8859-9?B?RXJ0YW4gS/zn/Gtv8Gx1?= <ertan.kucukoglu@1nar.com.tr> writes:
> I have below sql running fine on FirebirdSQL but not on PostgreSQL. As I am
> not the editor of the SQL, I cannot fix it to work with PostgreSQL. Any help
> is appreciated.

You're not being consistent about quoting, e.g. you've got this

>   COALESCE(DT.IAIK_OG, 0) AS "IAIK_OG",

which seems to be trying to reference this field of the DT subselect:

>     (sum(M.TES_IMARALANICIOG)/(select sum(I.ILC_IMARALANICI_OG) from
> ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IAIK_OG",

but it won't match because IAIK_OG is not the same name as "IAIK_OG".
(According to Postgres --- some other systems treat this differently.)
Best rule is to always quote a particular name or never quote it.

			regards, tom lane


-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: FirebirdSQL to PostgreSQL
@ 2017-09-12 20:22  Ertan Küçükoğlu <ertan.kucukoglu@1nar.com.tr>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 3+ messages in thread

From: Ertan Küçükoğlu @ 2017-09-12 20:22 UTC (permalink / raw)
  To: pgsql-sql

> -----Original Message-----
> From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Tom Lane
> Sent: Tuesday, September 12, 2017 3:11 PM
> To: Ertan Küçükoğlu <ertan.kucukoglu@1nar.com.tr>
> Cc: pgsql-sql@postgresql.org
> Subject: Re: [SQL] FirebirdSQL to PostgreSQL
>
> =?iso-8859-9?B?RXJ0YW4gS/zn/Gtv8Gx1?= <ertan.kucukoglu@1nar.com.tr> writes:
>> I have below sql running fine on FirebirdSQL but not on PostgreSQL. As 
>> I am not the editor of the SQL, I cannot fix it to work with 
>> PostgreSQL. Any help is appreciated.
>
> You're not being consistent about quoting, e.g. you've got this
>
>>    COALESCE(DT.IAIK_OG, 0) AS "IAIK_OG",
>
> which seems to be trying to reference this field of the DT subselect:
>
>>     (sum(M.TES_IMARALANICIOG)/(select sum(I.ILC_IMARALANICI_OG) from 
>>  ILCELER_TABLOSU I where I.ILCEADI = 'CÝHANBEYLÝ')*60) as "IAIK_OG",
>
> but it won't match because IAIK_OG is not the same name as "IAIK_OG".
> (According to Postgres --- some other systems treat this differently.) Best rule is to always quote a particular name or never quote it.
>
>			regards, tom lane

Thanks you Tom.

That was it. For now, I simply removed all quotes and query executed just fine.




-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2017-09-12 20:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-09-12 11:31 FirebirdSQL to PostgreSQL =?iso-8859-9?B?RXJ0YW4gS/zn/Gtv8Gx1?= <ertan.kucukoglu@1nar.com.tr>
2017-09-12 12:10 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-09-12 20:22   ` Ertan Küçükoğlu <ertan.kucukoglu@1nar.com.tr>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox