Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 September PostgreSQL: What are the Differences between SQL and PL/pgSQL language in Function

PostgreSQL: What are the Differences between SQL and PL/pgSQL language in Function

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

Most of the new PostgreSQL comers have doubt for SQL and PL/pgSQL language of PostgreSQL.

In the PostgreSQL, We can create function mainly using three languages like: SQL, PL/pgSQL, C programming.

PostgreSQL also supported lot many languages like: Perl, Python, Ruby, Java and others.

Most of the PostgreSQL Database Developers are using SQL and PL/pgSQL language.

What are the main differences between SQL and PL/pgSQL?

SQL Language:

  • This is a pure SQL only.
  • SQL language executes an arbitrary list of SQL statements and returning the result of the last query in the list.
  • SQL provides a very simple scalar query and It is not supported any query cache or query plan mechanism.
  • It is portable and easy to learn.
  • We cannot use any transaction command like: COMMIT, ROLLBACK and SAVEPOINT
  • When we do not require to return any value, We can define SQL functions as void.
  • For example,
    1
    2
    3
    CREATE FUNCTION fn_UpdateStudents() RETURNS void AS
    'UPDATE tbl_Students SET StudName=''Anvesh'' WHERE 1=2'
    LANGUAGE SQL;
  • We cannot use any VACUUM related commands in SQL Function.
  • We cannot use any prepared statements in SQL Function.
  • We can use SQL language for simple scalar queries because It does not support all other Procedural language feature like PL/pgSQL.(Features like: variables, loops, cursors, transaction command, query plan, query cache)
  • One of the disadvantage is, every SQL statement must be executed individually by the database server and all other queries have to wait for it to be processed.

PL/pgSQL Language:

  • PL/pgSQL is a procedural language, we can execute a block of statement inside the database server.
  • We can eliminate extra round trips between server and client.
  • We can use feature like: variable, dynamic query, cursor, trigger, transaction command and others.
  • Like SQL Language, we can also set a return value in PL/pgSQL.
  • We have N number of ways to write PL/pgSQL block for increasing the query performance.
  • All query plans can be cached and we can use as a prepared statement.
Sep 1, 2016Anvesh Patel
PostgreSQL 9.5: Introduced BRIN - Block Range Index with Performance ReportPostgreSQL: STRING_AGG() to Concatenate String Per Each Group (Like SQL Server STUFF())
Anvesh Patel
Anvesh Patel

Database Engineer

September 1, 2016 PostgreSQLAnvesh Patel, database, database research and development, dbrnd, plpgsql, Postgres Query, postgresql, PostgreSQL Administrator, PostgreSQL Error, PostgreSQL Programming, PostgreSQL Tips and Tricks, Procedure block, SQL, SQL vs PL/pgSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....