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 6751325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:54:48+00:00 2026-05-26T12:54:48+00:00

I want to know what PostgreSQL functions are. When do I have to write

  • 0

I want to know what PostgreSQL functions are.
When do I have to write them?
How can I write them?
And how can I call them?

  • 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-05-26T12:54:49+00:00Added an answer on May 26, 2026 at 12:54 pm

    Definition, from wikipedia:

    A stored procedure is a subroutine available to applications that
    access a relational database system.

    Advantages of stored procedures in general, from wikipedia:

    Overhead: Because stored procedure statements are stored directly in
    the database, they may remove all or part of the compilation overhead
    that is typically required in situations where software applications
    send inline (dynamic) SQL queries to a database. (…)

    Avoidance of network traffic: A major advantage with stored procedures
    is that they can run directly within the database engine. In a
    production system, this typically means that the procedures run
    entirely on a specialized database server, which has direct access to
    the data being accessed. The benefit here is that network
    communication costs can be avoided completely. This becomes
    particularly important for complex series of SQL statements.

    Encapsulation of business logic: Stored procedures allow programmers
    to embed business logic as an API in the database, which can simplify
    data management and reduce the need to encode the logic elsewhere in
    client programs. (…)

    Delegation of access-rights: In many systems, stored procedures can be
    granted access rights to the database that users who execute those
    procedures do not directly have.

    Some protection from SQL injection attacks: Stored procedures can be
    used to protect against injection attacks. Stored procedure parameters
    will be treated as data even if an attacker inserts SQL commands. (…)

    In PostgresSQL stored procedures are called user defined functions.
    Definition example:

    CREATE FUNCTION somefunc(quantity integer) RETURNS integer AS $$
    DECLARE
        myvariable integer := 2;
    BEGIN   
        RETURN quantity * myvariable;
    END;
    $$ LANGUAGE plpgsql;
    

    (You can use other languages to define stored functions in PostgreSQL)

    Calling example:

    SELECT somefunc(100);
    

    More info: http://www.postgresql.org/docs/9.1/static/server-programming.html

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

Sidebar

Related Questions

I want to know WHERE to write stored procedures in PostgreSQL? I mean not
I want to make DB but I just know MySQL and PostgreSQL. Can you
I want to know which tool can be used to measure the cyclomatic complexity
I want to know if i can create a custom google maps application,on which
I want to know what's the equivalent of Long data type in PostgreSQL?
I want to write documentation on my pet project. I have 30 tables and
I have a complex query in PostgreSQL and I want to use the result
I have two PostgreSQL functions. One returns a set of data, including an email
I want to know the basics of dynamic sql especially in PostgreSQL. I was
I have created a database in PostgreSQL, let's call it testdb . I have

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.