Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Z8SbJ-0000Cg-HO for pgsql-admin@arkaria.postgresql.org; Fri, 26 Jun 2015 12:19:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1Z8SbI-0004rk-On for pgsql-admin@arkaria.postgresql.org; Fri, 26 Jun 2015 12:19:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Z8SYC-0001iE-H2 for pgsql-admin@postgresql.org; Fri, 26 Jun 2015 12:16:08 +0000 Received: from mout.web.de ([212.227.15.4]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.84) (envelope-from ) id 1Z8SY5-00059V-38 for pgsql-admin@postgresql.org; Fri, 26 Jun 2015 12:16:07 +0000 Received: from vm-mailsrv.lan.net ([87.155.105.195]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0MQNzw-1ZVXIQ1Hg4-00ThIQ for ; Fri, 26 Jun 2015 14:15:58 +0200 Received: from localhost (localhost [127.0.0.1]) by vm-mailsrv.lan.net (Postfix) with ESMTP id CA5ACC81FB for ; Fri, 26 Jun 2015 14:15:57 +0200 (CEST) X-Spam-Flag: NO X-Spam-Score: -2.898 X-Spam-Level: X-Spam-Status: No, score=-2.898 tagged_above=-99.9 required=6.31 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, FREEMAIL_FROM=0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no Received: from vm-mailsrv.lan.net ([127.0.0.1]) by localhost (vm-mailsrv.lan.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ZZqQWwO_Ulou for ; Fri, 26 Jun 2015 14:15:51 +0200 (CEST) Received: from neslonek.homeunix.org (vm-webapp-ext.dmz-lan.net [192.168.0.100]) by vm-mailsrv.lan.net (Postfix) with ESMTP id B74A9C81F6 for ; Fri, 26 Jun 2015 14:15:51 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Date: Fri, 26 Jun 2015 14:15:51 +0200 From: Jan Lentfer To: Subject: Re: select query of mysql to postgres In-Reply-To: References: <77F5F8FA4B407F43BFCFD3FC3478969108EC9201@COVMSGCES-MBX01>, <77F5F8FA4B407F43BFCFD3FC3478969108EC9246@COVMSGCES-MBX01> Message-ID: <54d0aa5c08a565170ee35bf762f4ebc7@imap.lan.net> X-Sender: Jan.Lentfer@web.de User-Agent: Roundcube Webmail/0.7.2 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K0:L1PCSBJl6HO2H0PYobv7DhlalSQ59a2zIO0hGWVc4vJKhL9Yi1X LB0V77IHLBRORSpFDInZYhhNTSxD0clnh2QMWqahxLg7iHpORZ1H6llgFQekNz2ZksZhswW 3Aa1Z3FAVnTHAv/J9pRJDwb56VZK423VETa65Ol4YKKFDUa+Xnpgeb/5ctBmBaa0ZzsqaZF GTmAmWHZmKDJe0eS3h76w== X-UI-Out-Filterresults: notjunk:1;V01:K0:fxr8Vu9pt3Y=:rtgnDLAkLD6Fi+9MTPsWSw EEGpo+7bn7v8zCWfTHumdPcbpDTNw9FC8+RMamBseMUkIsY4vM7j2HRLRACnYB2phl8BpiZHG 4Y2F0O2SvqBeXwcv2GnTj6Wb6NuFV6Jf2zP2KM1TxWBLVholZF/8Iu7RufEHiyfTRR8ko5lw5 +BgQMJkJ+0wJjwuYInzZwxPIMb2nIutD9YgYstzmfyZjnvQgxza28IK5uJdbYBZpyJ6Pmxtuw VPkIAXGSRICpjOEdW5tghoh4jMnmo58iabBCrjRsGnMaLrFLqXvSuso1uz52WB7w8X21F+oqk L60iELvMbgjq3IIcLZzJpugKTtcbkVTun2N/L7EDpBh3pNJ4cR1EweAdAlkQvRmuclNc34rN5 tJ0xojzZuegcSyNjxP2nyIVNXjvBZ1o1qJc/gH+LbVUQp+Cjun348lBQl/P/vdW0QRwjPVJcz r43kRvxKK4WIplrU0plMdHFUACEPdEtaXotvB3dgGm5almVHCKNL1scMrllR1TudoHIekxj3i oRrGRPbDi7bhYRgN+hmJK4fGcnpK311V1k/276B4w+7BkN5BbxDh1L7tHZPcixeNLTHbCBlCG ejizLBh8CXC2bhDMCGJc1RC5aIYk2/EZpR3WZIcI96RpwAQOZrRJFLeAe5mP9rXJfeor+U0dd N4ytBz7NG4y5Jwkfox2kQaqCw+ZlHi8YI3/wqM9fgBz4oikPriWTQO8J220MqPLdBc6E= X-Pg-Spam-Score: -3.3 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org @VAR is T-SQL, Postgres does not support this. You will need to rewrite=20 the whole thing. https://en.wikipedia.org/wiki/Transact-SQL Regards Jan Am 2015-06-26 14:06, schrieb Holger.Friedrich-Fa-Trivadis@it.nrw.de: > Burgholzer, Robert (DEQ) wrote on Friday, June 26, 2015 1:59 PM: > > =C3=98 So this seems to be saying that postgres does not have the ifnull > function: >=20 > http://www.postgresql.org/docs/9.2/static/functions-conditional.htmlhttp:= //www.postgresql.org/docs/9.2/static/functions-conditional.html > [1] > > No, it seems to be saying that PostgreSQL did not understand the > @tot_dur :=3D @tot_dur part. > > If you format the error output with a fixed-pitch font, the ^ points > exactly to the :=3D operator.=C2=A0 (It seems to me that neither @ nor := =3D > exists in PostgreSQL.) > > LINE 8: ...fnull(rm.schedule_distance, 0)) IS NULL, @tot_dur :=3D > @tot_du... > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 > ^ > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 Best regards, > > Holger Friedrich > > ------------------------- > > FROM: Ankur Kaushik [ankurkaushik@gmail.com] > SENT: Friday, June 26, 2015 7:32 AM > TO: Burgholzer, Robert (DEQ) > CC: pgsql-admin@postgresql.org [2] > SUBJECT: Re: [ADMIN] select query of mysql to postgres > > Below is the error while executing the query. > > ERROR: syntax error at or near ":=3D" > > LINE 8: ...fnull(rm.schedule_distance, 0)) IS NULL, @tot_dur :=3D > @tot_du... > > ^ > > ********** Error ********** > > ERROR: syntax error at or near ":=3D" > > SQL state: 42601 > > Character: 474 > > On Fri, Jun 26, 2015 at 4:33 PM, Burgholzer, Robert (DEQ) > wrote: > > Two things - 1) Off the top of my head I would guess that the "@" > symbols refer to something that is mysql specific (or in my limited > postgresql experience, I have not seen/used it), 2) you should=20 > include > an error message, cause that will tell you what type of error and > approximate location, 3) to get help on this it may help other people > if you formatted your query in a way that was more legible. For > example: > > select bs.toll_zone, bs.toll_fee, > > concat(r.route_number,if(r.route_direction=3D'UP','UP','DN')) > route_number, > > route_order, r.route_id, > > ifnull(bs.bus_stop_code, bs.bus_stop_id) bus_stop_code, > > ifnull(bs.bus_stop_name, '') bus_stop_name, > > (ifnull(bs.bus_stop_name_nudi, '')) bus_stop_name_nudi, > > bs.bus_stop_id, ifnull(bs.alias1, '') alias1, > > IF( if(ifnull(rm.schedule_distance, 0)=3D'0',ifnull(rm.distance, > 0),ifnull(rm.schedule_distance, 0)) IS NULL, @tot_dur :=3D @tot_dur, > @tot_dur :=3D @tot_dur + if(ifnull(rm.schedule_distance, > 0)=3D'0',ifnull(rm.distance, 0),ifnull(rm.schedule_distance, 0)) )/1000 > AS tot_dist, ifnull(rp.sub_stage,'N') sub_stage, > ifnull(rp.fare_stage,'N') fare_stage,a.stage_count, rmd.adult, > rmd.children, rmd.senior_citizenfrom route r JOIN (SELECT @tot_dur :=3D > 0) d inner join route_point rp on rp.route_id =3D r.route_id inner join > bus_stop bs on bs.bus_stop_id=3Drp.bus_stop_id and bs.point_type_id!=3D2 > left join route_map rm on rm.start_bus_stop_id=3Drp.bus_stop_id and > rp.route_id=3D'3004' and rm.route_id=3D'3004' INNER JOIN (select=20 > route_id, > route_points_id, if(if(rp.fare_stage=3D'Y',1,0) IS NULL,@stage_count :=3D > @stage_count,@stage_count :=3D @stage_count+if(rp.fare_stage=3D'Y',1,0)) > as stage_count from route_point rp JOIN (SELECT @stage_count :=3D 0) e > where rp.route_id=3D'3004' ) aON rp.route_points_id =3D a.route_points_id > INNER JOIN rate_master_details rmd ON a.stage_count =3D rmd.stage_no=20 > AND > rmd.rate_master_id=3D'12'where r.route_id=3D'3004' AND bs.point_type_id > NOT IN ('2', '13') order by r.route_id; > > ------------------------- > > FROM: pgsql-admin-owner@postgresql.org [4] > [pgsql-admin-owner@postgresql.org [5]] on behalf of Ankur Kaushik > [ankurkaushik@gmail.com [6]] > SENT: Friday, June 26, 2015 4:13 AM > TO: pgsql-admin@postgresql.org [7] > SUBJECT: [ADMIN] select query of mysql to postgres > > I Have below query of mysql which is not executing in postgresql , > What changes need to do to execute in postgressql database > > select bs.toll_zone, bs.toll_fee, > concat(r.route_number,if(r.route_direction=3D'UP','UP','DN')) > route_number, route_order, r.route_id, ifnull(bs.bus_stop_code, > bs.bus_stop_id) bus_stop_code, ifnull(bs.bus_stop_name, '') > bus_stop_name, (ifnull(bs.bus_stop_name_nudi, ''))=20 > bus_stop_name_nudi, > bs.bus_stop_id, ifnull(bs.alias1, '') alias1, IF( > if(ifnull(rm.schedule_distance, 0)=3D'0',ifnull(rm.distance, > 0),ifnull(rm.schedule_distance, 0)) IS NULL, @tot_dur :=3D @tot_dur, > @tot_dur :=3D @tot_dur + if(ifnull(rm.schedule_distance, > 0)=3D'0',ifnull(rm.distance, 0),ifnull(rm.schedule_distance, 0)) )/1000 > AS tot_dist, ifnull(rp.sub_stage,'N') sub_stage, > ifnull(rp.fare_stage,'N') fare_stage,a.stage_count, rmd.adult, > rmd.children, rmd.senior_citizenfrom route r JOIN (SELECT @tot_dur :=3D > 0) d inner join route_point rp on rp.route_id =3D r.route_id inner join > bus_stop bs on bs.bus_stop_id=3Drp.bus_stop_id and bs.point_type_id!=3D2 > left join route_map rm on rm.start_bus_stop_id=3Drp.bus_stop_id and > rp.route_id=3D'3004' and rm.route_id=3D'3004' INNER JOIN (select=20 > route_id, > route_points_id, if(if(rp.fare_stage=3D'Y',1,0) IS NULL,@stage_count :=3D > @stage_count,@stage_count :=3D @stage_count+if(rp.fare_stage=3D'Y',1,0)) > as stage_count from route_point rp JOIN (SELECT @stage_count :=3D 0) e > where rp.route_id=3D'3004' ) aON rp.route_points_id =3D a.route_points_id > INNER JOIN rate_master_details rmd ON a.stage_count =3D rmd.stage_no=20 > AND > rmd.rate_master_id=3D'12'where r.route_id=3D'3004' AND bs.point_type_id > NOT IN ('2', '13') order by r.route_id; > > > > Links: > ------ > [1]=20 > http://www.postgresql.org/docs/9.2/static/functions-conditional.html > [2] mailto:pgsql-admin@postgresql.org > [3] mailto:Robert.Burgholzer@deq.virginia.gov > [4] mailto:pgsql-admin-owner@postgresql.org > [5] mailto:pgsql-admin-owner@postgresql.org > [6] mailto:ankurkaushik@gmail.com > [7] mailto:pgsql-admin@postgresql.org --=20 Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin