Re: database design questions

Lists: pgsql-general
From: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: database design questions
Date: 2006-04-03 14:38:03
Message-ID: 4431334B.90400@campana.vi.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hello,

I'm designing a database and I'm having some problems, so I ask you a
suggestion.

1) The database I'm going to develop is a big list with a catalog of
items and I want to store subsets of this list representing the
available items in several places.

My idea is to create the big table with all the elements and then to
create another table, where each row holds a pair (id_item, id_place)
and thanks to this create several views, joining the two tables
and selecting the rows with a give id_place.

Do you think it's too heavy? Is there a simpler way to do it?

2) do you think it's possible in a plpgsql procedure select the name of
a table into a variable and use that variable in the query?

I mean, can I do something like

SELECT INTO table_name get_table_name();
SELECT * FROM table_name;

?

3) faq 4.11.1 says

> CREATE TABLE person (
> id SERIAL,
> name TEXT
> );
>
>is automatically translated into this:
>
> CREATE SEQUENCE person_id_seq;
> CREATE TABLE person (
> id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
> name TEXT
> );

how can I do it with a INT8 instead of a INT4?

Thank you

--
Non c'è più forza nella normalità, c'è solo monotonia.


From: "Tomi NA" <hefest(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-03 14:50:34
Message-ID: d487eb8e0604030750t63444de4h5347ebf300fe312f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 4/3/06, Ottavio Campana <ottavio(at)campana(dot)vi(dot)it> wrote:

> 3) faq 4.11.1 says
>
> > CREATE TABLE person (
> > id SERIAL,
> > name TEXT
> > );
> >
> >is automatically translated into this:
> >
> > CREATE SEQUENCE person_id_seq;
> > CREATE TABLE person (
> > id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
> > name TEXT
> > );
>
> how can I do it with a INT8 instead of a INT4?
>
> Thank you
>

Is there a reason not to write explicitly?

CREATE SEQUENCE person_id_seq;
CREATE TABLE person (
id INT8 NOT NULL DEFAULT nextval('person_id_seq'),
name TEXT
);

Tomislav


From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-03 15:15:28
Message-ID: 20060403151528.80406.qmail@web31812.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

--- Tomi NA <hefest(at)gmail(dot)com> wrote:

> On 4/3/06, Ottavio Campana <ottavio(at)campana(dot)vi(dot)it> wrote:
>
>
> > 3) faq 4.11.1 says
> >
> > > CREATE TABLE person (
> > > id SERIAL,
> > > name TEXT
> > > );
> > >
> > >is automatically translated into this:
> > >
> > > CREATE SEQUENCE person_id_seq;
> > > CREATE TABLE person (
> > > id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
> > > name TEXT
> > > );
> >
> > how can I do it with a INT8 instead of a INT4?
> >
> > Thank you
> >
>
> Is there a reason not to write explicitly?
>
> CREATE SEQUENCE person_id_seq;
> CREATE TABLE person (
> id INT8 NOT NULL DEFAULT nextval('person_id_seq'),
> name TEXT
> );

you could also do:

CREATE TABLE person (
id BIGSERIAL,
name TEXT
);

Regards,

Richard


From: Alban Hertroys <alban(at)magproductions(dot)nl>
To: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-03 16:15:23
Message-ID: 44314A1B.8040701@magproductions.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Ottavio Campana wrote:
>> CREATE TABLE person (
>> id SERIAL,
>> name TEXT
>> );

> how can I do it with a INT8 instead of a INT4?

Do you really expect that sequence to reach over 2 billion? Otherwise
I'd stick with the SERIAL, nothing wrong with that unless you're selling
electrons seperately or something like that (hmm... how much are they? I
sure could use a few extra).

--
Alban Hertroys
alban(at)magproductions(dot)nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
7500 AK Enschede

// Integrate Your World //


From: "Alex Turner" <armtuk(at)gmail(dot)com>
To: "Alban Hertroys" <alban(at)magproductions(dot)nl>
Cc: "Ottavio Campana" <ottavio(at)campana(dot)vi(dot)it>, pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-03 16:26:35
Message-ID: 33c6269f0604030926n78edee2ck7f712c82faa80ab5@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

create table person (
id serial8,
name text
);

Alex

On 4/3/06, Alban Hertroys <alban(at)magproductions(dot)nl> wrote:
>
> Ottavio Campana wrote:
> >> CREATE TABLE person (
> >> id SERIAL,
> >> name TEXT
> >> );
>
> > how can I do it with a INT8 instead of a INT4?
>
> Do you really expect that sequence to reach over 2 billion? Otherwise
> I'd stick with the SERIAL, nothing wrong with that unless you're selling
> electrons seperately or something like that (hmm... how much are they? I
> sure could use a few extra).
>
> --
> Alban Hertroys
> alban(at)magproductions(dot)nl
>
> magproductions b.v.
>
> T: ++31(0)534346874
> F: ++31(0)534346876
> M:
> I: www.magproductions.nl
> A: Postbus 416
> 7500 AK Enschede
>
> // Integrate Your World //
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>


From: Keary Suska <hierophant(at)pcisys(dot)net>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: database design questions
Date: 2006-04-03 16:28:41
Message-ID: C0569B49.27C7B%hierophant@pcisys.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

on 4/3/06 7:38 AM, ottavio(at)campana(dot)vi(dot)it purportedly said:

> 1) The database I'm going to develop is a big list with a catalog of
> items and I want to store subsets of this list representing the
> available items in several places.
>
> My idea is to create the big table with all the elements and then to
> create another table, where each row holds a pair (id_item, id_place)
> and thanks to this create several views, joining the two tables
> and selecting the rows with a give id_place.
>
> Do you think it's too heavy? Is there a simpler way to do it?

On the surface, perhaps. Depending on your implementation details, you may
be adding unnecessary overhead. No one can really say since we don't know
what you are trying to accomplish.

> 2) do you think it's possible in a plpgsql procedure select the name of
> a table into a variable and use that variable in the query?
>
> I mean, can I do something like
>
> SELECT INTO table_name get_table_name();
> SELECT * FROM table_name;

Yes, kind of. I.e., you can probably do what you want but not with the
syntax you are showing. See SELECT INTO and EXECUTE in chapter 36 of the
online docs.

> 3) faq 4.11.1 says
>
>> CREATE TABLE person (
>> id SERIAL,
>> name TEXT
>> );
>>
>> is automatically translated into this:
>>
>> CREATE SEQUENCE person_id_seq;
>> CREATE TABLE person (
>> id INT4 NOT NULL DEFAULT nextval('person_id_seq'),
>> name TEXT
>> );
>
> how can I do it with a INT8 instead of a INT4?

Use BIGSERIAL instead.

Best,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


From: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>
To: Alban Hertroys <alban(at)magproductions(dot)nl>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-04 08:57:54
Message-ID: 44323512.4000207@campana.vi.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Alban Hertroys wrote:
> Ottavio Campana wrote:
>
>>> CREATE TABLE person (
>>> id SERIAL,
>>> name TEXT
>>> );
>
>
>> how can I do it with a INT8 instead of a INT4?
>
>
> Do you really expect that sequence to reach over 2 billion? Otherwise
> I'd stick with the SERIAL, nothing wrong with that unless you're selling
> electrons seperately or something like that (hmm... how much are they? I
> sure could use a few extra).

I agree wih you, but I think that in the feature the could be more than
2 billions. I don't want to alter in the future the database

--
Non c'è più forza nella normalità, c'è solo monotonia.


From: "hubert depesz lubaczewski" <depesz(at)gmail(dot)com>
To: "Ottavio Campana" <ottavio(at)campana(dot)vi(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-04 09:15:57
Message-ID: 9e4684ce0604040215l6bf56a38i34abee6b5a0f4ceb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 4/3/06, Ottavio Campana <ottavio(at)campana(dot)vi(dot)it> wrote:
>
> 1) The database I'm going to develop is a big list with a catalog of
> items and I want to store subsets of this list representing the
> available items in several places.
> My idea is to create the big table with all the elements and then to
> create another table, where each row holds a pair (id_item, id_place)
> and thanks to this create several views, joining the two tables
> and selecting the rows with a give id_place.
> Do you think it's too heavy? Is there a simpler way to do it?

sorry but i dont understand your description. could you make a small example
of this layout?

2) do you think it's possible in a plpgsql procedure select the name of
> a table into a variable and use that variable in the query?

possible, but not really good way. read about 'execute' in plpgsql.

3) faq 4.11.1 says
> how can I do it with a INT8 instead of a INT4?

use bigserial instead of serial

depesz


From: Ottavio Campana <ottavio(at)campana(dot)vi(dot)it>
To: hubert depesz lubaczewski <depesz(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-04 12:59:12
Message-ID: 44326DA0.5030009@campana.vi.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

hubert depesz lubaczewski wrote:
> 2) do you think it's possible in a plpgsql procedure select the name of
> a table into a variable and use that variable in the query?
> possible, but not really good way. read about 'execute' in plpgsql.

why isn't it good?

I mean, from my point of view is like a function accepting a pointer. In
many languages it is used.

--
Non c'è più forza nella normalità, c'è solo monotonia.


From: "hubert depesz lubaczewski" <depesz(at)gmail(dot)com>
To: "Ottavio Campana" <ottavio(at)campana(dot)vi(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: database design questions
Date: 2006-04-05 07:33:56
Message-ID: 9e4684ce0604050033w321a816hac33f4b9c7e16736@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 4/4/06, Ottavio Campana <ottavio(at)campana(dot)vi(dot)it> wrote:
>
> hubert depesz lubaczewski wrote:
> > 2) do you think it's possible in a plpgsql procedure select the
> name of
> > a table into a variable and use that variable in the query?
> > possible, but not really good way. read about 'execute' in plpgsql.
> why isn't it good?
> I mean, from my point of view is like a function accepting a pointer. In
> many languages it is used.
>

when coding in plpgsql you have to use dynamic queries to use this kind of
thing. this - by itself - is not bad. but it has certain performance penalty
when compared to standard queries.
i think reading plpgsql's manual about "execute" is the best one can do
about it :)

best regards

depesz