Unix Technical Forum

Problem with ROWs and UNION

This is a discussion on Problem with ROWs and UNION within the pgsql Bugs forums, part of the PostgreSQL category; --> Problem with ROW types in UNION. 1. UNION of ROW types fails with operator error. create type addrs as ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Bugs

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 08:50 AM
elein
 
Posts: n/a
Default Problem with ROWs and UNION

Problem with ROW types in UNION.

1. UNION of ROW types fails with operator error.

create type addrs as (
addr text,
city text,
state char(2),
zip text);

--
-- UNION of ROWS doesn't work (simply wrong)
--
select ROW('4514 Cherry St','Oakland','CA','94666')::addrs
UNION
select ROW('4515 Cherry St','Oakland','CA','94666')::addrs;
-- ERROR: could not identify an ordering operator for type addrs
-- HINT: Use an explicit ordering operator or modify the query.

--
-- But select * containing rows does work.
--
create table people (
name text,
fname text,
addr addrs
);
insert into people values ('ae','aem',ROW('4514 Cherry St','Oakland','CA','94666') );
insert into people values ('go','ggo',ROW('4515 Cherry St','Oakland','CA','94666') );

select * from people;
name | fname | addr
------+-------+-------------------------------------
ae | aem | ("4514 Cherry St",Oakland,CA,94666)
go | ggo | ("4515 Cherry St",Oakland,CA,94666)
(2 rows)


================================================== ===========
elein@varlena.com Varlena, LLC www.varlena.com
(510)655-2584(o) (510)543-6079(c)
PostgreSQL Consulting, Support & Training

PostgreSQL General Bits http://www.varlena.com/GeneralBits/
================================================== ============
I have always depended on the [QA] of strangers.


---------------------------(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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 08:50 AM
Alvaro Herrera
 
Posts: n/a
Default Re: Problem with ROWs and UNION

On Thu, May 12, 2005 at 12:32:48PM -0700, elein wrote:

> --
> -- UNION of ROWS doesn't work (simply wrong)
> --
> select ROW('4514 Cherry St','Oakland','CA','94666')::addrs
> UNION
> select ROW('4515 Cherry St','Oakland','CA','94666')::addrs;
> -- ERROR: could not identify an ordering operator for type addrs
> -- HINT: Use an explicit ordering operator or modify the query.


UNION ALL does work:

alvherre=# select ROW('4514 Cherry St','Oakland','CA','94666')::addrs
UNION ALL
select ROW('4515 Cherry St','Oakland','CA','94666')::addrs;
row
-------------------------------------
("4514 Cherry St",Oakland,CA,94666)
("4515 Cherry St",Oakland,CA,94666)
(2 filas)


I think the error message is misleading though, because the user has no
way to specify the ordering operator to UNION.

I think you could create a btree operator class to make it all work.

--
Alvaro Herrera (<alvherre[a]surnet.cl>)
"And as an added bonus, now my computer goes to the toilet for me, leaving me
free to spend time on more useful activities! yay slug codefests!" (C. Parker)

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 08:50 AM
elein
 
Posts: n/a
Default Re: Problem with ROWs and UNION

On Thu, May 12, 2005 at 03:57:18PM -0400, Alvaro Herrera wrote:
> On Thu, May 12, 2005 at 12:32:48PM -0700, elein wrote:
>
> > --
> > -- UNION of ROWS doesn't work (simply wrong)
> > --
> > select ROW('4514 Cherry St','Oakland','CA','94666')::addrs
> > UNION
> > select ROW('4515 Cherry St','Oakland','CA','94666')::addrs;
> > -- ERROR: could not identify an ordering operator for type addrs
> > -- HINT: Use an explicit ordering operator or modify the query.

>
> UNION ALL does work:
>
> alvherre=# select ROW('4514 Cherry St','Oakland','CA','94666')::addrs
> UNION ALL
> select ROW('4515 Cherry St','Oakland','CA','94666')::addrs;
> row
> -------------------------------------
> ("4514 Cherry St",Oakland,CA,94666)
> ("4515 Cherry St",Oakland,CA,94666)
> (2 filas)


This makes sense because the UNION needs to have the ordering/
comparative operators to eliminate duplicates.

It is a work around, but I think there needs to be a ROW
ordering operator added.

>
>
> I think the error message is misleading though, because the user has no
> way to specify the ordering operator to UNION.
>
> I think you could create a btree operator class to make it all work.
>



--elein
elein@varlena.com

---------------------------(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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-10-2008, 08:50 AM
Tom Lane
 
Posts: n/a
Default Re: Problem with ROWs and UNION

Alvaro Herrera <alvherre@surnet.cl> writes:
> I think you could create a btree operator class to make it all work.


Hm. Given that we've managed to build a general opclass for arrays,
I suppose it should be possible for records too. Hardly trivial though.

A closely related point is fixing row comparisons to obey the SQL
semantics properly.

regards, tom lane

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:55 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com