Warning
As pgx
is being renamed to pgrx
, this repository is outdated. Please
head over to https://github.com/kw7oe/pgrx_string_demo for the updated version.
This project includes a simple PostgreSQL extension written in
Rust, using the pgx
crate. This extension contains the following
string manipulations functions:
to_title
: Convert a given string to title case.emojify
: Convert any emoji shortcode in a string to emoji.
This is extension is for demonstration and learning purposes and by no mean for using it in production.
If you would like to learn more about it you can refer to this post:
Writing PostgreSQL extension in Rust With pgx
- Install and setup
cargo-pgx
. For more, refer to the Getting Started ofpgx
cargo install cargo-pgx
cargo pgx init
- Clone this repository and change directory into it.
- Run it using
cargo pgx run pg14
. This will spin up a PostgreSQL. - In your
psql
session, load the extension first:
pgx_strings=# create extension pgx_strings;
CREATE EXTENSION
pgx_strings=# \df
List of functions
Schema | Name | Result data type | Argument data types | Type
--------+-------------------+------------------+---------------------+------
public | emojify | text | string text | func
public | hello_pgx_strings | text | | func
public | to_title | text | string text | func
(3 rows)
- Now with everything loaded you can run the following SQL:
pgx_strings=# select hello_pgx_strings();
hello_pgx_strings
--------------------
Hello, pgx_strings
(1 row)
pgx_strings=# select to_title('this is so cool');
to_title
-----------------
This Is So Cool
(1 row)
pgx_strings=# select emojify('I love pgx :100:');
emojify
--------------
I love pgx 💯
(1 row)