Base64 PostgreSQL Extension
This is just part of my learning process
Clone
$ git clone https://github.com/wuriyanto48/pgwbase64.git
Install PostgreSQL Development server and client
$ sudo apt install libpq-dev
$ sudo apt-get install -y postgresql-server-dev-10
Compile extensions, Create and Copy SHARED Library to /usr/lib/postgresql/10/lib/
$ cc -fPIC -c wbase64.c -I /usr/include/postgresql/10/server/
$ cc -shared -o wbase64.so wbase64.o
$ sudo cp wbase64.so /usr/lib/postgresql/10/lib/
To find out what $libdir
is referring to, run the following command:
$ pg_config --pkglibdir
/usr/lib/postgresql/10/lib
Install extensions
$ sudo make USE_PGXS=1 install
Login as superuser
$ sudo --login --user postgres
$ psql
Connect to specific Database
$ \c database_name;
Show installed extensions
$ select extname from pg_extension;
Drop extensions
$ DROP EXTENSION IF EXISTS wbase64;
Create extensions
$ CREATE EXTENSION IF NOT EXISTS wbase64;
Encode
database_name=# select pgw_b64_encode('this is dark') as res;
res
------------------
dGhpcyBpcyBkYXJr
(1 row)
Decode
database_name=# select pgw_b64_decode('dGhpcyBpcyBkYXJr') as res;
res
--------------
this is dark
(1 row)