Обсуждение: simple linking question

Поиск
Список
Период
Сортировка

simple linking question

От
Jeremy Hansen
Дата:
I'm trying to do some more advanced things in sql to make my tables more
efficient.  I'd like to do a link, or perhaps it's a join, although
everything I've looked at relating to a join makes me think that it's not
what I'm looking for.

What I would like to do is have a field in a table retrieve its data from
a field in another table.  The idea is not to have duplicated information
in two different tables.  Is this possible to do with postgres?  I studied
join selects, but it seems this method requires that information be
duplicated in a third table.  I want to avoid duplicating data.

Or is this just stupid?

Thanks for any help or pointers to documentation.

-jeremy

--
salad.




Re: simple linking question

От
Justin Clift
Дата:
Hi Jeremy,

It sounds like what you're saying is that you have data in Table A, and
you also have data in Table B, but you want one of the fields in Table B
to really be from a field in Table A at all times (transparently).  Is
that right?

You could create a VIEW using the "CREATE VIEW" command
(http://www.postgresql.org/idocs/index.php?sql-createview.html).  It's
kind of like creating Table C - but it's a dynamically updated virtual
table whose data really comes from other tables (it doesn't have any
real data of it's own).

Kind of like this :

       -------
       Table C
       -------
          ^
          |
   ---------------
   |             |
-------       -------
Table A       Table B
-------       -------

(Did this line art in Netscape, so I'm not sure if it'll work in your
mail reader)

And you use normal everyday SQL queries with Table C, and they
automatically redirect to the fields from Table A and Table B
appropriately.  It's not really all that hard to setup either.  Well,
not if you're mainly going to be doing SELECT statements on the new
"Table C".  Get's a little more tedious setting things up if you want to
do changes through a VIEW.

Does that help?

:-)

Regards and best wishes,

Justin Clift


Jeremy Hansen wrote:
>
> I'm trying to do some more advanced things in sql to make my tables more
> efficient.  I'd like to do a link, or perhaps it's a join, although
> everything I've looked at relating to a join makes me think that it's not
> what I'm looking for.
>
> What I would like to do is have a field in a table retrieve its data from
> a field in another table.  The idea is not to have duplicated information
> in two different tables.  Is this possible to do with postgres?  I studied
> join selects, but it seems this method requires that information be
> duplicated in a third table.  I want to avoid duplicating data.
>
> Or is this just stupid?
>
> Thanks for any help or pointers to documentation.
>
> -jeremy
>
> --
> salad.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html