Обсуждение: SOS, help me please, one problem towards the postgresql developement on windows

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

SOS, help me please, one problem towards the postgresql developement on windows

От
shieldy
Дата:

my postgresql source code is at c:/mingw/postgresql and instal to C:/msys/1.0/local/pgsql/
I add a function to src\backend\utils\adt\geo_ops.c as the following:
Datum
box_add2(PG_FUNCTION_ARGS)
{
 BOX     *box = PG_GETARG_BOX_P(0);
 Point    *p = PG_GETARG_POINT_P(1);

 PG_RETURN_BOX_P(box_construct((box->high.x + 2* p->x),
          (box->low.x + 2* p->x),
          (box->high.y +2* p->y),
          (box->low.y + 2* p->y)));
}
there is another similar one(this is the original one):
Datum
box_add(PG_FUNCTION_ARGS)
{
 BOX     *box = PG_GETARG_BOX_P(0);
 Point    *p = PG_GETARG_POINT_P(1);

 PG_RETURN_BOX_P(box_construct((box->high.x + p->x),
          (box->low.x + p->x),
          (box->high.y + p->y),
          (box->low.y + p->y)));
}

And i also add the declaration to the src\include\utils\geo_decls.h like this:

extern Datum box_add2(PG_FUNCTION_ARGS);

and then I did the following like step by step:


$ cd /c/mingw/postgresql
$ ./configure
....
///as i download the alib, but don't kown where it should be put. so i ignore this, does it

matter????
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.
$ make
...
All of PostgreSQL successfully made. Ready to install.
$ make install
....
PostgreSQL installation complete.
$ initdb -D /usr/local/pgsql/data           //before this i add the environments

variableslike this:
PGDATA=C:/msys/1.0/local/pgsql/data
PGHOME=C:/msys/1.0/local/pgsql
PGHOST=localhost
PGPORT=5434
PATH= C:/msys/1.0/local/pgsql/bin
.....
Success. You can now start the database server using:

    "C:\msys\1.0\local\pgsql\bin\postgres" -D "C:/msys/1.0/local/pgsql/data"
or
    "C:\msys\1.0\local\pgsql\bin\pg_ctl" -D "C:/msys/1.0/local/pgsql/data" -l logfile start

$ pg_ctl start -l logfile
server starting

$ createdb testdb
CREATE DATABASE

then I use pgadminIII to open the database:
just run the scripts:
select box_add(box '((0,0),(1,1))',point'(2,2)')
got:
(3,3),(2,2)

select box_add2(box '((0,0),(1,1))',point'(2,2)')
got:
ERROR: function box_add2(box, point) does not exist
SQL state: 42883
advice:No function matches the given name and argument types. You may need to add explicit
type casts.
chars:8

anyone know this??? why this happened? what should I do?
thankyou very much!!!

 


Re: SOS, help me please, one problem towards the postgresql developement on windows

От
Martijn van Oosterhout
Дата:
On Mon, Apr 30, 2007 at 01:36:36AM +0800, shieldy wrote:
> >
> >my postgresql source code is at c:/mingw/postgresql and instal to
> >C:/msys/1.0/local/pgsql/
> >I add a function to src\backend\utils\adt\geo_ops.c as the following:

A few things:
- You never did a CREATE FUNCTION so ofcourse the DB doesn't know about
it
- Why are you adding it to the backend? Place it in a module.
- Read the manual on how to create new functions
- look at the examples in the contrib directory.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Re: SOS, help me please, one problem towards the postgresql developement on windows

От
"FAST PostgreSQL"
Дата:
I assume you are trying to create a built-in function, right?

If thats the case you may want to create an entry in pg_proc (That seems
to be missing). Search for box_add in the source code and you will get
an idea what code needs to be added where.

Rgds,
Arul Shaji


shieldy wrote:
>     my postgresql source code is at c:/mingw/postgresql and instal to
>     C:/msys/1.0/local/pgsql/
>     I add a function to src\backend\utils\adt\geo_ops.c as the following:
>     /Datum
>     box_add2(PG_FUNCTION_ARGS)
>     {
>      BOX     *box = PG_GETARG_BOX_P(0);
>      Point    *p = PG_GETARG_POINT_P(1);/
> 
>     / PG_RETURN_BOX_P(box_construct((box->high.x + 2* p->x),
>               (box->low.x + 2* p->x),
>               (box->high.y +2* p->y),
>               (box->low.y + 2* p->y)));
>     }
>     /there is another similar one(this is the original one):
>     /Datum
>     box_add(PG_FUNCTION_ARGS)
>     {
>      BOX     *box = PG_GETARG_BOX_P(0);
>      Point    *p = PG_GETARG_POINT_P(1);/
> 
>     / PG_RETURN_BOX_P(box_construct((box->high.x + p->x),
>               (box->low.x + p->x),
>               (box->high.y + p->y),
>               (box->low.y + p->y)));
>     }/
>     And i also add the declaration to the src\include\utils\geo_decls.h
>     like this:
> 
>     extern Datum box_add2(PG_FUNCTION_ARGS);
> 
>     and then I did the following like step by step:
> 
> 
>     $ cd /c/mingw/postgresql
>     $ ./configure
>     ....
>     ///as i download the alib, but don't kown where it should be put. so
>     i ignore this, does it
> 
>     matter????
>     configure: error: zlib library not found
>     If you have zlib already installed, see config.log for details on the
>     failure.  It is possible the compiler isn't looking in the proper
>     directory.
>     Use --without-zlib to disable zlib support.
>     $ make
>     ...
>     All of PostgreSQL successfully made. Ready to install.
>     $ make install
>     ....
>     PostgreSQL installation complete.
>     $ initdb -D /usr/local/pgsql/data           //before this i add the
>     environments
> 
>     variableslike this:
>     PGDATA=C:/msys/1.0/local/pgsql/data
>     PGHOME=C:/msys/1.0/local/pgsql
>     PGHOST=localhost
>     PGPORT=5434
>     PATH= C:/msys/1.0/local/pgsql/bin
>     .....
>     Success. You can now start the database server using:
> 
>         "C:\msys\1.0\local\pgsql\bin\postgres" -D
>     "C:/msys/1.0/local/pgsql/data"
>     or
>         "C:\msys\1.0\local\pgsql\bin\pg_ctl" -D
>     "C:/msys/1.0/local/pgsql/data" -l logfile start
> 
>     $ pg_ctl start -l logfile
>     server starting
> 
>     $ createdb testdb
>     CREATE DATABASE
> 
>     then I use pgadminIII to open the database:
>     just run the scripts:
>     /select box_add(box '((0,0),(1,1))',point'(2,2)')/
>     got:
>     (3,3),(2,2)
> 
>     /select box_add2(box '((0,0),(1,1))',point'(2,2)')/
>     got:
>     *ERROR: function box_add2(box, point) does not exist
>     SQL state: 42883
>     advice:No function matches the given name and argument types. You
>     may need to add explicit **type casts.
>     chars:8*
> 
>     anyone know this??? why this happened? what should I do?
>     thankyou very much!!!
> 
>      
> 
> 



Re: SOS, help me please, one problem towards the postgresql developement on windows

От
shieldy
Дата:
thankyou very much.
but the method, you said, is adding a alias name, so it can not work.
and as i need to add many functions likes this, so the best way is to compile the whole postgresql. eventhough, i did, it didnot work, so i am puzzled, can add a function directly in the source file, and compile it, can it work??
BTW: I have just seach the source for addingthe built-in function, and found it need to add declaration in the include geo_decls.h, and add the function in the geo_ops.c. can it not be enough??


 
On 5/1/07, Martijn van Oosterhout <kleptog@svana.org> wrote:
On Mon, Apr 30, 2007 at 11:05:35AM +0800, shieldy wrote:
> thankyou for your reply.
> I added it to the backend, because the internal ones such as box_intersect()
> function is keeped at there. so in my opinion, I just need to add a function
> to the files, and then compile it. then we can use it as the internal ones.
> bytheway, what's the backend file used for? I just didnot quite understand
> the postgresql.  and your meaning " place it in a module" , how should i
> do??

First, please reply to the list, not to me directly.

Secondly, just because you add it to the backend doesn't mean you can
use it straight away. There are thousands of functions in postgresql you
can't access from SQL, you have to declare them. See here:

http://www.postgresql.org/docs/8.2/interactive/xfunc-internal.html

Finally, by putting it in the backend you have to rebuild postgres
every time you want to change a function. Complete waste of time as
postgres can load external modules. See here:

http://www.postgresql.org/docs/8.2/interactive/xfunc-c.html

Or better, just read the whole "Extending SQL" section.

http://www.postgresql.org/docs/8.2/interactive/extend.html

Have a nice day,
--
Martijn van Oosterhout   < kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFGNwoKIB7bNG8LQkwRAjXuAJ9atldhI9Q81lIuRpD8Egguv5ojvgCcCk4v
/Jkr0WGrKP9mxN94iw9X3/U=
=Swve
-----END PGP SIGNATURE-----