Unix Technical Forum

Recursive types?

This is a discussion on Recursive types? within the pgsql Hackers forums, part of the PostgreSQL category; --> Consider the following: create table foo ( id serial primary key, path text); alter table foo add ref foo; ...


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

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 04:23 AM
John Hansen
 
Posts: n/a
Default Recursive types?

Consider the following:

create table foo ( id serial primary key, path text);
alter table foo add ref foo;

Table "public.foo"
Column | Type | Modifiers
--------+---------+-----------------------------------------------------
id | integer | not null default nextval('public.foo_id_seq'::text)
path | text |
ref | foo |
Indexes:
"foo_pkey" PRIMARY KEY, btree (id)


insert into foo (path) VALUES ('/');
insert into foo (path,ref) VALUES ('/foo',ROW(1,'/',NULL));
insert into foo (path,ref) VALUES
('/foo/bar',ROW(2,'/foo',ROW(1,'/',NULL)));

select * from foo;
id | path | ref
----+----------+-------------------
1 | / |
2 | /foo | (1,/,)
3 | /foo/bar | (2,/foo,"(1,/,)")
(3 rows)

However, it is not possible to create such a type using create type, as
there is no alter type, even tho alter table does the same thing.

Is this a bug or a random feature?

It is also not possible to dump and restore this using pg_dump.

.... John

---------------------------(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
  #2 (permalink)  
Old 04-11-2008, 04:23 AM
Tom Lane
 
Posts: n/a
Default Re: Recursive types?

"John Hansen" <john@geeknet.com.au> writes:
> create table foo ( id serial primary key, path text);
> alter table foo add ref foo;


> Is this a bug or a random feature?


I'd say it's a random misfeature ;-). I certainly don't care to promise
that it's supported ... but on the other hand, preventing you from doing
it seems nontrivial (consider indirect recursions). I'd put this in the
category of "doctor, it hurts when I do that".

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: 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 03:55 AM.


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