First off, it appears you want a built in type. That would allow you to:
a) store data in the form you'd like it
b) perform operations on that data as you'd like
Those are the two things you need to be able to do in order to have an
"object".
So, let's take you're example of an address that contains 3 text attributes:
address_one
address_two
zip_code
I'll assume from this point that you'd like to be able to do only the basic
operations: set the value and retrieve the value.
Let's say you'd like to use the following form (this won't work yet, I am
just writing out our *goal* for functionality):
create table my_table(
my_col my_object
);
INSERT INTO my_table (my_col) values('{"123 first st","456 second
st","99999"}');
and then if you do SELECT * FROM my_table;
you get:
my_col
-------------------------
123 first st
456 second st
99999
Now, how do we make that work?
We really just need to define the input/output functions (creating functions
is a seperate topic, so consult the docs and ask a seperate question if
you're having trouble with that), and then create the type:
Let's say you have an input function named "my_object_input" that processes
and input of the form '{"123 first st","456 second st","99999"}' (like in my
example) and then stores it in more sensible format (i.e. break it up and
store as seperate strings).
Also, you need an output function that takes the internally stored data and
presents it. Call it my_object_output. Then create the type by:
CREATE TYPE my_object (
INPUT = my_object_input,
OUTPUT = my_object_output,
INTERNALLENGTH = VARIABLE
);
I hope this sets you on the right track. Consult the documentation and try a
few things out, and then email me if you have any more questions. Please
include specific queries that you've tried, and show me your point of
difficulty.
Regards,
Jeff
On Tuesday 25 June 2002 12:15 am, Kalyan Shanker wrote:
> Hi Jeff,
> Thank you very much for your prompt reply.. I actually want to create an
> object for example.. Object - Address which can hold three value like First
> Address, Second Address, Zip code.. What is the syntax to create the same.
> More over i also want to assign a array of such object in the table.. I
> need the syntax to create such object and also table with array of that
> obj. Could u pls help in this regard
> Awaiting your earliest response..
> Thanks in advance
> Shanker.K
>
> Jeff Davis <list-pgsql-general@empires.org> wrote: It's not entirely
> clear what you want the database to do for you, but it looks like pgsql's
> "create type" command would help you out. A created type takes input,
> processes it, stores it, and provides a way of displaying the data. You can
> also provide operations for the data so that it works with indexes or that
> kind of thing.
>
> Regards,
> Jeff
>
> On Monday 24 June 2002 03:55 am, Shanker wrote:
> > Hi PostgreSQL expert,
> >
> > How to make an object in PostgreSQL.. For example I can make object in
> > oracle like "Create Type as Object ...." Finally i also
> > want to make array of object in the table. Could any PostgreSQL
> > expert help me on this issue.
> >
> > Awaiting for your reply
> >
> > Thanks in advance
> >
> > Shanker.K
> >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
> ---------------------------------
> Do You Yahoo!?
> Sign-up for Video Highlights of 2002 FIFA World Cup