Unix Technical Forum

table inheritance

This is a discussion on table inheritance within the pgsql Novice forums, part of the PostgreSQL category; --> Hi, I've got table x and table y which inherits table x. I want to get items from table ...


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

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 10:36 PM
Shuying Wang
 
Posts: n/a
Default table inheritance

Hi,

I've got table x and table y which inherits table x. I want to get
items from table x which are not in table y. According to the
PostgreSQL documentation, the syntax would be "select * FROM ONLY x"
however this yields no rows, whereas something like "select * from x
where id not in (select id from y) " gives me what I want. Could
someone explain to me what I'm doing wrong using ONLY?

Thanks in advance,
Shuying

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 10:36 PM
Michael Fuhr
 
Posts: n/a
Default Re: table inheritance

On Wed, Feb 22, 2006 at 04:39:12PM +1100, Shuying Wang wrote:
> I've got table x and table y which inherits table x. I want to get
> items from table x which are not in table y. According to the
> PostgreSQL documentation, the syntax would be "select * FROM ONLY x"
> however this yields no rows, whereas something like "select * from x
> where id not in (select id from y) " gives me what I want. Could
> someone explain to me what I'm doing wrong using ONLY?


Do any other tables inherit x? What's the output of the following
query?

SELECT tableoid::regclass, * FROM x WHERE id NOT IN (SELECT id FROM y);

Could you show a simple but complete test case? It works fine here
in 8.1.3:

CREATE TABLE x (id integer);
CREATE TABLE y () INHERITS (x);

INSERT INTO x VALUES (1);
INSERT INTO x VALUES (2);
INSERT INTO y VALUES (3);
INSERT INTO y VALUES (4);

SELECT * FROM ONLY x;
id
----
1
2
(2 rows)

SELECT * FROM x;
id
----
1
2
3
4
(4 rows)

--
Michael Fuhr

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 10:36 PM
Shuying Wang
 
Posts: n/a
Default Re: table inheritance

Actually, it's my fault. It turns out that the parent table was empty
and there was some other table that had all the other data.

Thanks, that was a quick response.
--Shuying

On 2/22/06, Michael Fuhr <mike@fuhr.org> wrote:
> On Wed, Feb 22, 2006 at 04:39:12PM +1100, Shuying Wang wrote:
> > I've got table x and table y which inherits table x. I want to get
> > items from table x which are not in table y. According to the
> > PostgreSQL documentation, the syntax would be "select * FROM ONLY x"
> > however this yields no rows, whereas something like "select * from x
> > where id not in (select id from y) " gives me what I want. Could
> > someone explain to me what I'm doing wrong using ONLY?

> Do any other tables inherit x? What's the output of the following
> query?


---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

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 04:08 PM.


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