473,799 Members | 3,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug: 8.0 beta1 either view optimization or pgdump/pgrestore

I just did a dump and restore of my database and one of my views did
not recreate.

The error received was :
pg_restore.exe: [archiver (db)] could not execute query: ERROR: column reference "pricinggroupid " is ambiguous

I checked the function in the original database, using PGAdmin, and
the system seemed to have slightly changed my query.
Part of my query was a virtual table (i.e joining on (select *
from ...) as tablename ) and the system changed that to:
(select fielda,fieldb,f ieldc from...) the problem is that there were
joined tables in that virtual table with identical fieldnames. As
the optimizer did not qualify the field names with the table names, it
makes ambiguous columns. That being said, the view does work after it
is created.

I assume this is a bug in the view optimization.

Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #1
5 2337
Sim Zacks <si*@compulab.c o.il> writes:
I just did a dump and restore of my database and one of my views did
not recreate. The error received was :
pg_restore.exe: [archiver (db)] could not execute query: ERROR: column reference "pricinggroupid " is ambiguous I checked the function in the original database, using PGAdmin, and
the system seemed to have slightly changed my query.
Part of my query was a virtual table (i.e joining on (select *
from ...) as tablename ) and the system changed that to:
(select fielda,fieldb,f ieldc from...) the problem is that there were
joined tables in that virtual table with identical fieldnames.


The view creation should have failed to begin with, then. Could we see
the *exact* problem and not a handwavy description?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
OOps. Didn't send it to the list. (There has to be a better way of
doing this then always having to remember to change the recipient.)

I'm sorry, I thought I described the problem pretty clearly.
Here is the actual queries with comment annotations where the problem
occurred.

1) This is the query that I typed in:
create or replace view qry_AssembliesM issingInfo as
SELECT a.AssemblyID, a.AssemblyName, a.PackageID, a.Package, a.SupplierID, a.NumPins, case when numpins is null then '' else 'Num Pins Not Specified. ' end || case when PackagePricingG roupID is null then '' else 'Package Not in a Pricing Group. ' end || case when (PackagePricing GroupID is not null And BasePrice is null) Or PricePerPin is null then 'Group Prices are Not Configured' else '' end AS Problem
FROM qry_AssembliesM issingInfo1 a LEFT JOIN

/*Here is the virtual table I mentioned using select * on a join*/
(select * from PackagePricingG roups b Inner JOIN PricingGroups c ON b.PricingGroupI D = c.PricingGroupI D) groups

ON a.PackageID = groups.PackageI D AND a.SupplierID = groups.Supplier ID
WHERE (a.NumPins Is Null AND groups.BasePric e Is Null) OR (groups.BasePri ce Is Null AND groups.PricePer Pin Is Null)
OR (coalesce(Price PerPin,0)>0 and coalesce(NumPin s,0)=0)
GROUP BY a.AssemblyID, a.AssemblyName, a.PackageID, a.Package, a.SupplierID, a.NumPins, case when numpins is null then '' else 'Num Pins Not Specified. ' end || case when PackagePricingG roupID is null then '' else 'Package Not in a Pricing Group. ' end || case when (PackagePricing GroupID is not null And BasePrice is null) Or PricePerPin is null then 'Group Prices are Not Configured' else '' end, groups.BasePric e, groups.PricePer Pin;
2) This is what PGAdmin shows after I have created view:
-- View: "qry_assemblies missinginfo"

-- DROP VIEW qry_assembliesm issinginfo;

CREATE OR REPLACE VIEW qry_assembliesm issinginfo AS
SELECT a.assemblyid, a.assemblyname, a.packageid, a.package, a.supplierid, a.numpins, (
CASE
WHEN numpins IS NULL THEN ''::text
ELSE 'Num Pins Not Specified. '::text
END ||
CASE
WHEN packagepricingg roupid IS NULL THEN ''::text
ELSE 'Package Not in a Pricing Group. '::text
END) ||
CASE
WHEN packagepricingg roupid IS NOT NULL AND baseprice IS NULL OR priceperpin IS NULL THEN 'Group Prices are Not Configured'::te xt
ELSE ''::text
END AS problem
FROM qry_assembliesm issinginfo1 a

/*Here is where the problem comes in as you can see there are a
number of fields with the same name, such as pricinggroupid,
createuserid... */

LEFT JOIN ( SELECT packagepricingg roupid, pricinggroupid, packageid, createuserid, createdate, modifyuserid, modifydate, pricinggroupid, description, supplierid, baseprice, priceperpin, currencyid, createuserid, createdate, modifyuserid, modifydate
FROM packagepricingg roups b
JOIN pricinggroups c ON b.pricinggroupi d = c.pricinggroupi d) groups ON a.packageid = groups.packagei d AND a.supplierid = groups.supplier id
WHERE a.numpins IS NULL AND groups.basepric e IS NULL OR groups.basepric e IS NULL AND groups.priceper pin IS NULL OR COALESCE(pricep erpin, 0::double precision) > 0::double precision AND COALESCE(numpin s, 0) = 0
GROUP BY a.assemblyid, a.assemblyname, a.packageid, a.package, a.supplierid, a.numpins, (
CASE
WHEN numpins IS NULL THEN ''::text
ELSE 'Num Pins Not Specified. '::text
END ||
CASE
WHEN packagepricingg roupid IS NULL THEN ''::text
ELSE 'Package Not in a Pricing Group. '::text
END) ||
CASE
WHEN packagepricingg roupid IS NOT NULL AND baseprice IS NULL OR priceperpin IS NULL THEN 'Group Prices are Not Configured'::te xt
ELSE ''::text
END, groups.basepric e, groups.priceper pin;

3) Exactly what happened.
My view worked fine after I created it.
I did a Backup using PGAdmin (which uses pg_dump)
I did a restore to a new database using PGAdmin (which uses PG_restore)
The restore gave me the ambiguous error I mentioned before
on that view.
I took the PGAdmin version of my view and saw that it had
extrapolated the fields from * and that was causing the
ambiguity. I then changed it back to * and executed the
create or replace view statement.
The view now works again.

Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax

_______________ _______________ _______________ _______________ _______________ _____

Sim Zacks <si*@compulab.c o.il> writes:
I just did a dump and restore of my database and one of my views did
not recreate. The error received was :
pg_restore.exe: [archiver (db)] could not execute query: ERROR: column reference "pricinggroupid " is ambiguous I checked the function in the original database, using PGAdmin, and
the system seemed to have slightly changed my query.
Part of my query was a virtual table (i.e joining on (select *
from ...) as tablename ) and the system changed that to:
(select fielda,fieldb,f ieldc from...) the problem is that there were
joined tables in that virtual table with identical fieldnames.
The view creation should have failed to begin with, then. Could we see
the *exact* problem and not a handwavy description?

regards, tom lane

Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax

_______________ _______________ _______________ _______________ _______________ _____

Sim Zacks <si*@compulab.c o.il> writes: I just did a dump and restore of my database and one of my views did
not recreate. The error received was :
pg_restore.exe: [archiver (db)] could not execute query: ERROR: column reference "pricinggroupid " is ambiguous I checked the function in the original database, using PGAdmin, and
the system seemed to have slightly changed my query.
Part of my query was a virtual table (i.e joining on (select *
from ...) as tablename ) and the system changed that to:
(select fielda,fieldb,f ieldc from...) the problem is that there were
joined tables in that virtual table with identical fieldnames.


The view creation should have failed to begin with, then. Could we see
the *exact* problem and not a handwavy description?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #3
Sim Zacks <si*@compulab.c o.il> writes:
/*Here is the virtual table I mentioned using select * on a join*/
(select * from PackagePricingG roups b Inner JOIN PricingGroups c ON b.PricingGroupI D = c.PricingGroupI D) groups


Okay, evidently the problem is that you have identically named
columns in the two tables PackagePricingG roups and PricingGroups,
so the "groups" join contains duplicate column names. (AFAICS this
is not illegal per the SQL spec, but I wonder whether it shouldn't
be, because it's very hard to avoid ambiguity.)

I've tweaked ruleutils.c for 8.0 so that the display looks like

....
LEFT JOIN ( SELECT b.packagepricin ggroupid, b.pricinggroupi d,
b.packageid, b.createuserid, b.createdate, b.modifyuserid,
b.modifydate, c.pricinggroupi d, c.description,
c.supplierid, c.baseprice, c.priceperpin, c.currencyid,
c.createuserid, c.createdate, c.modifyuserid, c.modifydate
FROM packagepricingg roups b
JOIN pricinggroups c ON
....

which solves this particular issue. I'm not sure a complete solution is
possible in the presence of duplicate column names; perhaps you should
modify the query to avoid that.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #4
As I was not using any of those duplicate columns, * was easier to use
and I did not think about trying to use the other ones.
In fact when you do try to use one of those columns in the query, it
doesn't allow the query because of ambiguous columns.

Thank you for fixing this particular problem, even though it doesn't
solve the global question it does allow you to seamlessly backup and
restore functions that work correctly in PG. I do not think that
anything needs to be answered in this regards, because if you wanted
to actually use any of those fields it would give you the same
ambiguity error and you would have to change the query to use aliases
for the identical field names. In any case, a query trying to use identical
field names would not work to begin with, so there is no call to fix
anything so long as it does not change existing behavior.

Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax

_______________ _______________ _______________ _______________ _______________ _____

Sim Zacks <si*@compulab.c o.il> writes:
/*Here is the virtual table I mentioned using select * on a join*/
(select * from PackagePricingG roups b Inner JOIN PricingGroups c ON b.PricingGroupI D = c.PricingGroupI D) groups


Okay, evidently the problem is that you have identically named
columns in the two tables PackagePricingG roups and PricingGroups,
so the "groups" join contains duplicate column names. (AFAICS this
is not illegal per the SQL spec, but I wonder whether it shouldn't
be, because it's very hard to avoid ambiguity.)

I've tweaked ruleutils.c for 8.0 so that the display looks like

....
LEFT JOIN ( SELECT b.packagepricin ggroupid, b.pricinggroupi d,
b.packageid, b.createuserid, b.createdate, b.modifyuserid,
b.modifydate, c.pricinggroupi d, c.description,
c.supplierid, c.baseprice, c.priceperpin, c.currencyid,
c.createuserid, c.createdate, c.modifyuserid, c.modifydate
FROM packagepricingg roups b
JOIN pricinggroups c ON
....

which solves this particular issue. I'm not sure a complete solution is
possible in the presence of duplicate column names; perhaps you should
modify the query to avoid that.

regards, tom lane
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 23 '05 #5
On second thought another way to optimize a query like that would be
to remove the * and only put in the columns that are actually being
used, as opposed to taking the * literally.
Such that if the fields in the select list use 2 columns and the join
uses 1 column, only those 3 columns should be expanded by the
optimizer. This would probably make the query more efficient as well,
being that it selects fewer fields.

Thank You
Sim Zacks
IT Manager
CompuLab
04-829-0145 - Office
04-832-5251 - Fax
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3753
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are using the Debug-Version of the program, but it fails (or leads to false results) if we are using the Release-Version. After a long debugging session we found out, that our program was working correctly, but the floating point processing...
4
2235
by: Neil | last post by:
I just resolved a strange situation I was having with an ODBC linked SQL 7 view in an Access 2000 MDB file, and I'm trying to get some understanding as to what happened. The linked view was scrolling very slowly in the MDB file; however, it scrolled very quickly when accessed through an ADP file. Theoretically, since it's a server-side object, it should appear the same in both files, but it didn't. Not knowing what was causing this, I...
6
3965
by: Thorsten Raasch | last post by:
Hi, the following C++ program seems to yield a segmentation fault in g++ 3.4 when compiled with any of the optimization options -O*, e.g. with "g++ -O2 bug.cpp -o bug". class TestClass { public:
19
3582
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and one web presentation tier (Foo.WebFiles). The data tier shall only be accessible thru the business tier so I do NOT want a reference to the data tier in the presentation tier. In the business tier I have a class with the name CategoryItem that...
19
1820
by: Jerry | last post by:
I managed to narrow this down to a very simple expression. try this: private void Bug() { bool b = false; Test(3, (b || b) && b && !b); } private void Works() {
1
1009
by: Christian | last post by:
I'm new to this list so please forgive in case this is not the correct forum. If so, please let me know to where I can direct bug reports for vc. The following crashes using whole program optimization (i.e. invoking LTCG) under vc7.1 Professional. #include <string> #include <boost/function.hpp> #include <boost/bind.hpp>
0
1143
by: Glen Parker | last post by:
8.0 beta1 does not run on Windows 2000 Terminal Server. This is the http://pgfoundry.org/projects/pginstaller/ download from 08/09/2004. It ran OK for me on Win2K Pro, so I suspect this is caused by the terminal server stuff; I have experienced differences in shared memory code between terminal server and non terminal server in the past. postmaster throws this error immediately. FATAL: could not create shared memory segment: No error
3
2253
by: Abhishek | last post by:
Recently i found that my C++ program was running fine with no optimization and giving segmentation fault with error code 139 when compiled with optimization level 2. I searched somewhat but never find any systematic solution. In my recent attempt, i found the problem with the optimization tool itself, which iam discussing here. I found that the problem of segmentation fault was boiled down to a statement of the form A = B, with no...
38
2306
by: Mark Dickinson | last post by:
I get the following behaviour on Python 2.5 (OS X 10.4.8 on PowerPC, in case it's relevant.) (0.0, 0.0) (-0.0, -0.0) I would have expected y to be -0.0 in the first case, and 0.0 in the second. Should the above be considered a bug, or is Python not expected to honour signs of zeros? I'm working in a situation involving complex arithmetic where branch cuts, and hence signed
0
10485
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10252
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10231
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9073
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.