Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8186531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:14:23+00:00 2026-06-07T02:14:23+00:00

At work we currently have a PostgreSQL database and we access it via some

  • 0

At work we currently have a PostgreSQL database and we access it via some Perl bindings to access the database and marshal responses to Perl types. This works OK, but for various reasons we are becoming unhappy with Perl. One option we’ve been considering is to move the majority of the work in this API to the database itself as plpgsql stored procedures.

Brief Example

For example, we might have the following in the database:

-- This matches our 'Entity::Artist' object
CREATE TYPE loaded_artist (
  artist_id uuid,
  revision_id integer,
  artist_tree_id integer,
  name text,
  sort_name text,
  artist_type_id integer,
  -- etc
);

-- This gets the latest 'master' version of an artist and joins in basic data
-- from the artist tree
CREATE FUNCTION get_latest_artist_by_mbid(in_mbid UUID)
RETURNS SETOF loaded_artist AS $$
  BEGIN
    RETURN QUERY
    SELECT
      artist_id, revision_id, artist_tree_id, name.name,
      sort_name.name AS sort_name, artist_type_id
    FROM artist
    JOIN artist_revision USING (artist_id)
    JOIN artist_tree USING (artist_tree_id)
    JOIN artist_data USING (artist_data_id)
    WHERE artist.master_revision_id = revision_id
      AND artist_id = in_mbid;
  END;
$$ LANGUAGE 'plpgsql';

Now our current Perl API can be simplified to effectively the following:# And in Perl

package Data::Artist;
sub get_latest_by_mbid {
    my ($self, $mbid) = @_;
    return $self->new_from_row(
        $self->sql->select_single_row_hash(
            'SELECT * FROM get_latest_artist_by_mbid(?)',
            $mbid));
}

Is this sensible?

On face value, I like this. We:

  • Move away from Perl, but don’t commit to another language. This means we can move our actual application to Python/whatever in the future and the majority of our API is already done.
  • Get extra type safety from PostgreSQL due to specifying things like RETURNS SETOF loaded_artist
  • Still have unit tests and stuff via PGTAP.

There are a few disadvantages:

  • Potentially lower development cycle as we now have to replace functions in the database. Not the end of the world, but this effectively introduces a ‘compile’ step into our workflow that was not previously there.
  • Potentially more difficult version control, but there are certainly ways of doing it

Has anyone done work like this? Would you encourage it, or was it fraught with peril?


Footnote: A little more about our case

This is for an open source website. We distribute dumps of our database for people to import into PostgreSQL databases. We have no plans to move away from PG any time soon, so database agnostic decisions don’t really apply to us. We are a very small team (2 paid developers, more open source contributors) and this lets us be quite flexible in terms of deployment strategies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T02:14:25+00:00Added an answer on June 7, 2026 at 2:14 am

    Advantages:

    • database schema / layout / storage changes are completely hidden from the application;
    • you have a unified API to work with the database;
    • you can have extensive logging on all actions done in the database, including all SELECT queries.

    Disadvantages:

    • increased need in the good DBAs;
    • increased need in the database developers with good understanding of how database is working with data and how DB-side procedures work;
    • more coordination will be required between DB-side and Application-side teams;
    • difficulties with ORM integration;
    • using stored procedures limits optimization possibilities of the database and some queries (especially reports) will be giving performance issues, it is better to use views instead, as optimizer can push down predicates into the view and utilize indexes properly.

    Best combination is when you implement a deal of your business logic on the database side and not only wrapper functions.

    Schema version control is possible. It is more tricky to version the data in the configuration tables. In one of the project I’m involved this is done via the external tool (perl based) that handles this part for us:

    • data is loaded / extracted into intermediate tables first;
    • then it is analyzed for RI constraints and all possible violations;
    • data manipulations are possible before loading it into live tables;
    • business objects that spawns multiple tables can be defined and extracted in one go;
    • several ways of treating matching entities exists, like: overwrite, merge, duplicate.

    We’re versioning the extract files instead (which a plain SQL) and have a special step in the installation script to load the new configuration.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this jquery but it won't work. if it helps my url
I currently have event.stopPropagation() to work on a few selectors, but now I need
I currently work in the position of Data Warehouse programmer and as such have
I'm currently having difficulty finding a way of making my loops work. I have
I have been trying to get this to work correctly and I think I
At work we currently have a custom in-house built winforms app for the business
At work we currently have a very large web application with a connection to
I currently have this: redirect 301 ^/about/ /about.html redirect 301 ^/about/skills/ /skills.html redirect 301
We're currently migrating our database back-end from Firebird to PostgreSQL. We use NHibernate as
I currently have an svn repository on my hosted web server. I work locally,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.