Reverse engineering problem on views

Lists: pgadmin-supportpgsql-patches
From: laurie(dot)burrow(at)powerconv(dot)alstom(dot)com
To: pgadmin-support(at)postgresql(dot)org
Subject: Reverse engineering problem on views
Date: 2004-12-06 13:25:09
Message-ID: OF72DC7EB4.AADD76C8-ON80256F62.0046FD3D-80256F62.004AD0F9@transport.alstom.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-patches

Hi,

I have noticed this possible bug:

Using pgadmin V1.2.0 on Windows 2000 Desktop to a remote Windows 2000
Server Postgres V7.4.1 running on cygwin and to Postgres V8Beta2

Created this view.

CREATE OR REPLACE VIEW public.test_view AS
SELECT or0.actvle AS treename
FROM gnrcitm g
LEFT JOIN (gnrcitmothrref g0
JOIN other_ref r0 ON g0.idntfyrefid = r0.idntfyrefid AND
r0.catnmeclssid::text = 'Tree Name'::text) or0 ON g.gnrcitmid =
or0.gnrcitmid

Retrieved view into SQL dialog window using copy SQL option

This gave

-- View: "test_view"

-- DROP VIEW test_view;

CREATE OR REPLACE VIEW test_view AS
SELECT or0.actvle AS treename
FROM gnrcitm g
LEFT JOIN ((gnrcitmothrref g0
JOIN other_ref r0 ON g0.idntfyrefid = r0.idntfyrefid AND
r0.catnmeclssid::text = 'Tree Name'::text) or0) ON g.gnrcitmid =
or0.gnrcitmid;

When executed this gives ERROR: syntax error at or near ")" at character
273.

There seems to be an error caused by the reverse engineering adding the
extra bracketting on the left join clauses. If the extra brackets are
deleted the SQLis executed correctly.

Any suggestions?

Great work pgadmin, really enjoy using it.

Regards
Laurie Burrow

:.________________
CONFIDENTIALITY : This e-mail and any attachments are confidential and
may be privileged. If you are not a named recipient, please notify the
sender immediately and do not disclose the contents to another person, use
it for any purpose or store or copy the information in any medium.


From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: laurie(dot)burrow(at)powerconv(dot)alstom(dot)com
Cc: pgadmin-support(at)postgresql(dot)org, Dave Page <dpage(at)vale-housing(dot)co(dot)uk>
Subject: Re: Reverse engineering problem on views
Date: 2004-12-10 11:34:15
Message-ID: 41B989B7.9060204@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-patches

laurie(dot)burrow(at)powerconv(dot)alstom(dot)com wrote:

> Retrieved view into SQL dialog window using copy SQL option
>
> This gave
>
> -- View: "test_view"
>
> -- DROP VIEW test_view;
>
> CREATE OR REPLACE VIEW test_view AS
> SELECT or0.actvle AS treename
> FROM gnrcitm g
> LEFT JOIN ((gnrcitmothrref g0
> JOIN other_ref r0 ON g0.idntfyrefid = r0.idntfyrefid AND
> r0.catnmeclssid::text = 'Tree Name'::text) or0) ON g.gnrcitmid =
> or0.gnrcitmid;
>
> When executed this gives ERROR: syntax error at or near ")" at character
> 273.

I can confirm this; the backend's pg_get_viewdef will give these
parentheses too much with pretty-print option=true. Quite awkward, since
this option should *suppress* additional parens...

I'll check the backend code.

Regards,
Andreas


From: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
Cc: laurie(dot)burrow(at)powerconv(dot)alstom(dot)com, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: pg_get_viewdef returns one paren too much
Date: 2004-12-10 13:55:01
Message-ID: 41B9AAB5.4030900@pse-consulting.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-patches

laurie(dot)burrow(at)powerconv(dot)alstom(dot)com noticed a problem with pg_get_viewdef
in prettyprint mode.

create table gnrcitm (gnrcitmid int);
create table gnrcitmothrref (idntfyrefid int, gnrcitmid int);
create table other_ref(idntfyrefid int, catnmeclssid text, actvle text);

CREATE OR REPLACE VIEW test_view AS
SELECT or0.actvle AS treename
FROM gnrcitm g
LEFT JOIN (gnrcitmothrref g0
JOIN other_ref r0 ON g0.idntfyrefid = r0.idntfyrefid AND
r0.catnmeclssid::text = 'Tree Name'::text) or0
ON g.gnrcitmid = or0.gnrcitmid;

pg_get_viewdef(viewoid, true) will return

CREATE OR REPLACE VIEW test_view AS
SELECT or0.actvle AS treename
FROM gnrcitm g
LEFT JOIN
( -- <<<
(gnrcitmothrref g0
JOIN other_ref r0 ON g0.idntfyrefid = r0.idntfyrefid AND
r0.catnmeclssid = 'Tree Name'::text) or0
) -- <<<
ON g.gnrcitmid = or0.gnrcitmid;

The attached patch corrects this, without affecting the following:

CREATE OR REPLACE VIEW test_view2 AS
SELECT r0.actvle AS treename
FROM gnrcitm g
LEFT JOIN (gnrcitmothrref g0
JOIN other_ref r0 ON g0.idntfyrefid = r0.idntfyrefid AND
r0.catnmeclssid::text = 'Tree Name'::text)
ON g.gnrcitmid = g0.gnrcitmid

Regards,
Andreas

Attachment Content-Type Size
ruleutils.diff text/x-patch 634 bytes

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Andreas Pflug <pgadmin(at)pse-consulting(dot)de>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, laurie(dot)burrow(at)powerconv(dot)alstom(dot)com, PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: pg_get_viewdef returns one paren too much
Date: 2004-12-13 00:34:04
Message-ID: 13695.1102898044@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgadmin-support pgsql-patches

Andreas Pflug <pgadmin(at)pse-consulting(dot)de> writes:
> laurie(dot)burrow(at)powerconv(dot)alstom(dot)com noticed a problem with pg_get_viewdef
> in prettyprint mode.

Applied in HEAD and 7.4 branches.

regards, tom lane