In Postgresql, If you want to do something like “select Hello(a) from A;”. You should define your own function Hello().
First, go to postgresql root directory and go into contrib file folder. Create your own directory, and add hello.h , hello.c, Makefile, hello.sql.in and uninstall_Hello.sql.in
Makefile is like the following:
|
|
Attention!!! In Makefile those command should be with no blank at end.
Here we can write hello.sql.in:
|
|
Here is the uninstall_Hello.sql.in:
|
|
In hello.h
|
|
hello.c
|
|
|
|
Then cd your folder contrib/Hello, make, and make install
Then start psql to execute :
create table A(a HelloS);
insert into A values(‘cc’);
insert into A values(‘ff’);
select Hello(a) from A;
result:
Hello cc
Hello ff
select * from A;
result:
cc
ff