views:

731

answers:

8

Postgresql is interesting in that it supports several languages for writing stored procedures. Which one do you use, and why?

+1  A: 

When I wrote my first trigger it was in Perl because that was the language used in the example I found but the last triggers I wrote where in Python because I'm more comfortable with that.

I think programmer comfort is my main reason to choose python but I think Perl is still better supported.

sparkes
+4  A: 

I have only really used PL/SQL, but that was because I needed a few stored procedures relatively fast and didn't want to add extra modules to the server.

Longer term, I would probably use PL/Perl or PL/Python, as I use perl for quick scripting and have been looking at python for a while now.

One thing I have found is that there is a lack of good documentation for that on the PostGRESQL site. The manuals were thorough as a reference, but did not work well as a tutorial to help show people how it should be done.

That, combined with a very good debugging environment, meant that my first experience of writing procedures involved looking at weird syntax errors for a long time.

Thankfully, I found a couple of very useful forums for this:

http://www.postgresqlforums.com/forums/

If someone does know of a good site with tutorials etc for PostGRESQL programming, I would love to get a link to it.

kaybenleroll
+2  A: 

Skype uses PostgreSQL together with python, and they have improved PL/Python to it's current state so I would doubt that python support is far behind perl. They have written queuing/replication system on top of those bindings, after all :-) Take a look: https://developer.skype.com/SkypeGarage/DbProjects/SkyTools

From a quick look in documentation, python seems to have less documentation than perl bindings, but I would suggest to just stick with language you are most comfortable with.

dpavlin
+2  A: 

I write pretty much everything in plpgsql, but I'm also a database guy first and foremost, so it generally suits me better than any other language. But there's plenty of things that it doesn't do very well, in which case another language such as plperl or plpython is a good bet. Of course, if speed is a serious concern, C is the way to go.

decibel
yeah, I started using pl/python for something and read about the security concerns and then looked over plpgsql and found it did everything I want pretty simply. I like it.
Arthur Thomas
+1  A: 

For anything really small/simple or that doesn't require a lot of string manipulation or logic, I use plpgsql, because it's fast. For more complex things, I use plperl, because I like it.

Flimzy
+1  A: 

PL/Ruby because I use Ruby every day anyway.

Thanatos
As a PL/Ruby user, would you have any idea on my question athttp://stackoverflow.com/questions/617600/installing-pl-ruby-for-postgresql ?-- Thanks
Mike Berrow
+1  A: 

I use PL/pgSQL for most everything, and if there is something it can't do I write functions in PL/Python (which rocks). You can also use PL/Java, PL/Perl, PL/PHP.

I would say Python is probably the best all around one because Python is on just about every linux system. Perl would be second with Python beating it because of the easier reading syntax.

+1  A: 

I use PL/Perl because:

  • I like Perl
  • It's a dynamic language, which means that you can do some useful tricks easy, i.e. passing a column name to a trigger function and doing some actions with the value of this column in a trigger tuple.
  • It has a pretty good documentation
Alexey Klyukin