Обсуждение: user defined types and strings

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

user defined types and strings

От
Kjetil Haaland
Дата:
Hi

I have made a user defined type which has a string of variable length and and
an integer value. Since the string is of variable length i have used a
pointer for the string. When i use this type as a column in a table and
inserts values into it, the string will go away. I understand that this is
because i am pointing to a place in memory for the string, and that this wont
last for a very long time. So i am wondering how i am supposed to use strings
in a user defined type so they will be saved in the database when the type is
inserted in a table?

-Kjetil

Re: user defined types and strings

От
Michael Fuhr
Дата:
On Wed, Feb 23, 2005 at 02:01:36PM +0100, Kjetil Haaland wrote:

> I have made a user defined type which has a string of variable length and and
> an integer value. Since the string is of variable length i have used a
> pointer for the string. When i use this type as a column in a table and
> inserts values into it, the string will go away. I understand that this is
> because i am pointing to a place in memory for the string, and that this wont
> last for a very long time. So i am wondering how i am supposed to use strings
> in a user defined type so they will be saved in the database when the type is
> inserted in a table?

Hmmm...haven't we already had this conversation? :-)

http://archives.postgresql.org/pgsql-novice/2004-11/msg00096.php
http://archives.postgresql.org/pgsql-novice/2004-11/msg00106.php

The type's data needs to be a contiguous block of memory, preceded
by four bytes (int32) indicating the total length (including the
four bytes).  You should also be aware of how TOAST works and the
need to use PG_DETOAST_DATUM in certain places.

http://www.postgresql.org/docs/8.0/static/xtypes.html
http://www.postgresql.org/docs/8.0/static/storage-toast.html

Or have I misunderstood what you're asking?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Re: user defined types and strings

От
Kjetil Haaland
Дата:
On Wednesday 23 February 2005 18:23, Michael Fuhr wrote:
> Hmmm...haven't we already had this conversation? :-)
>
> http://archives.postgresql.org/pgsql-novice/2004-11/msg00096.php
> http://archives.postgresql.org/pgsql-novice/2004-11/msg00106.php
>
> The type's data needs to be a contiguous block of memory, preceded
> by four bytes (int32) indicating the total length (including the
> four bytes).  You should also be aware of how TOAST works and the
> need to use PG_DETOAST_DATUM in certain places.
>
> http://www.postgresql.org/docs/8.0/static/xtypes.html
> http://www.postgresql.org/docs/8.0/static/storage-toast.html
>
> Or have I misunderstood what you're asking?

We have had almost the same conversation before. The type works in my
functions, but since the string is just a pointer to a memory place it goes
away when the type is stored in tables in the database. I have read about the
TOAST stuff, and think i have to use this because i have a pointer, and that
the actual values have to be found elsewhere. Is this correct? But i don't
understand how this is used. I have tried to add the line

pg_detoast_datum((struct varlena*) DatumGetPointer(result));

in my input function after i have allocated the memory for the structure and
the string. I also set the length variable before i do this. But it still
want save what's in the string. I have also tried to add it in the output
function right after i have recieved the argument. But this doesn't help. Is
there any examples i can look at to see how TOAST is used?

thanks for all the help so far!
-Kjetil

shutdown postmaster question

От
Дата:
i use the following commands to start the postmaster
on my development winxp / cygwin / pgsql 7.4.5
setup...

1.

/usr/sbin/cygserver &

2.

postmaster -i -D /usr/share/postgresql/data &

before getting to my real question, what do the "&"
characters do?

now to the real question...  how do i shut down the
postmaster?  i checked the docs bu it wasn't clear.  i
tried their example and it didn't work.

i read about the signals... SIGTERM, SIGINT, or
SIGQUIT, but i don't how to implement them since the
example given didn't work.  any help woul dbe greatly
appreciated.

i have been shutting down cygwin to end pgsql, but my
guess is that isn't the best way to shut it down.

tia...



__________________________________
Do you Yahoo!?
Take Yahoo! Mail with you! Get it on your mobile phone.
http://mobile.yahoo.com/maildemo

Re: shutdown postmaster question

От
George Weaver
Дата:
You might find starting and stopping postmaster easier by using pg_ctl.  Eg
in a batch file the following will stop the server:

bash pg_ctl stop -D /usr/share/postgresql/data

Regards,
George


----- Original Message -----
From: <operationsengineer1@yahoo.com>
To: <pgsql-novice@postgresql.org>
Sent: Wednesday, February 23, 2005 3:17 PM
Subject: [NOVICE] shutdown postmaster question


>i use the following commands to start the postmaster
> on my development winxp / cygwin / pgsql 7.4.5
> setup...
>
> 1.
>
> /usr/sbin/cygserver &
>
> 2.
>
> postmaster -i -D /usr/share/postgresql/data &
>
> before getting to my real question, what do the "&"
> characters do?
>
> now to the real question...  how do i shut down the
> postmaster?  i checked the docs bu it wasn't clear.  i
> tried their example and it didn't work.
>
> i read about the signals... SIGTERM, SIGINT, or
> SIGQUIT, but i don't how to implement them since the
> example given didn't work.  any help woul dbe greatly
> appreciated.
>
> i have been shutting down cygwin to end pgsql, but my
> guess is that isn't the best way to shut it down.
>
> tia...
>
>
>
> __________________________________
> Do you Yahoo!?
> Take Yahoo! Mail with you! Get it on your mobile phone.
> http://mobile.yahoo.com/maildemo
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>



Re: user defined types and strings

От
Tom Lane
Дата:
Kjetil Haaland <kjetil.haaland@student.uib.no> writes:
> On Wednesday 23 February 2005 18:23, Michael Fuhr wrote:
>> Hmmm...haven't we already had this conversation? :-)

> We have had almost the same conversation before. The type works in my
> functions, but since the string is just a pointer to a memory place it goes
> away when the type is stored in tables in the database.

The point here is that you've built a two-part structure:

    <length> <pointer to string> <some other fields>
                    |
                    +------------> text of string

and this is fundamentally not going to work.  A datum has to be one
piece of memory.  Consider something like

    <length> <some other fields> <text of string>

where the length is now variable.

            regards, tom lane

Re: shutdown postmaster question

От
Дата:
--- George Weaver <gweaver@shaw.ca> wrote:

>
> You might find starting and stopping postmaster
> easier by using pg_ctl.  Eg
> in a batch file the following will stop the server:
>
> bash pg_ctl stop -D /usr/share/postgresql/data
>
> Regards,
> George
>
>
> ----- Original Message -----
> From: <operationsengineer1@yahoo.com>
> To: <pgsql-novice@postgresql.org>
> Sent: Wednesday, February 23, 2005 3:17 PM
> Subject: [NOVICE] shutdown postmaster question
>
>
> >i use the following commands to start the
> postmaster
> > on my development winxp / cygwin / pgsql 7.4.5
> > setup...
> >
> > 1.
> >
> > /usr/sbin/cygserver &
> >
> > 2.
> >
> > postmaster -i -D /usr/share/postgresql/data &
> >
> > before getting to my real question, what do the
> "&"
> > characters do?
> >
> > now to the real question...  how do i shut down
> the
> > postmaster?  i checked the docs bu it wasn't
> clear.  i
> > tried their example and it didn't work.
> >
> > i read about the signals... SIGTERM, SIGINT, or
> > SIGQUIT, but i don't how to implement them since
> the
> > example given didn't work.  any help woul dbe
> greatly
> > appreciated.
> >
> > i have been shutting down cygwin to end pgsql, but
> my
> > guess is that isn't the best way to shut it down.
> >
> > tia...
> >
> >
> >
> > __________________________________
> > Do you Yahoo!?
> > Take Yahoo! Mail with you! Get it on your mobile
> phone.
> > http://mobile.yahoo.com/maildemo
> >
> > ---------------------------(end of
> broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the
> unregister command
> >    (send "unregister YourEmailAddressHere" to
> majordomo@postgresql.org)


i tried pg_ctl with no luck.  i started with

pg_ctl start

but my pgdata environment variable wasn't set and i
couldn't quickly find out how to set it via the docs.

i then tried

pg_ctl /usr/share/postgresql/data start

and received an invalid operation mode error.

i'm not sure how pg_ctl handles the "-i" issue (tcp/ip
connections) and whether the trailing "&" is required
using pg_ctl.  the docs and my php/pgsql book were
unclear after an admittedly quick review.



__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail

Re: shutdown postmaster question

От
George Weaver
Дата:
I have used 2 batch files in the past.

The first was start.bat with the lines

    bash pg_ctl start -D /usr/share/postgresql/data -o -i

    pause

stop.bat contained:

    bash pg_ctl stop -D /usr/share/postgresql/data


----- Original Message -----
From: <operationsengineer1@yahoo.com>
To: "George Weaver" <gweaver@shaw.ca>; <pgsql-novice@postgresql.org>
Sent: Thursday, February 24, 2005 12:27 PM
Subject: Re: [NOVICE] shutdown postmaster question


>
> --- George Weaver <gweaver@shaw.ca> wrote:
>
>>
>> You might find starting and stopping postmaster
>> easier by using pg_ctl.  Eg
>> in a batch file the following will stop the server:
>>
>> bash pg_ctl stop -D /usr/share/postgresql/data
>>
>> Regards,
>> George
>
> i tried pg_ctl with no luck.  i started with
>
> pg_ctl start
>
> but my pgdata environment variable wasn't set and i
> couldn't quickly find out how to set it via the docs.

See -D abvove

> i then tried
>
> pg_ctl /usr/share/postgresql/data start
>
> and received an invalid operation mode error.
>
> i'm not sure how pg_ctl handles the "-i" issue (tcp/ip
> connections) and whether the trailing "&" is required
> using pg_ctl.  the docs and my php/pgsql book were
> unclear after an admittedly quick review.

-o is needed to pass options directly to the postmaster e.g. -i

Regards,
Geroge