DEV Community

andi
andi

Posted on

1 1

plpythonu PL/Python - on snake inside elephant

like this but another way around

actually we would to something another way around ;) snake inside the elephant, not the other way around like in the little prince story.

good intro can be this talk available on youtube:

pywaw talk on plpythonu by Jan Urbanski

followed by it's slides: https://wulczer.org/pywaw-summit.pdf

prelude - what do you need to setup in your postgres?

if you play with plpython3u on fresh postgres instance you will probably need install/setup the following:

apt-get update
apt-get install postgresql-plpython3-11
  • be careful to install good version for your postgres version:

inside psql:

CREATE EXTENSION plpython3u;

example fun

create function histogram(a float[], bins int = 10)
returns int[]
as $$
import numpy
return numpy.histogram(a, bins)[0]
$$ language plpython3u;
  • you may need install on postgres machine additional python libraries (e.g numpy for above), first install pip: apt-get install python3-pip

Important things to remember:

  • keep you functions in separated module with option to mock plpython magic, so these are GOOD tested

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay