Skip to navigation | Skip to content

Share your knowledge. Make a difference.

All About PostgreSQL

1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic (by 0 people)   Your rating: 1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic

Ranked #4189 in Tech, #90218 overall

Rated G. (Control what you see)

Welcome to All About PostgreSQL

 

This lens aggregates postgresql news, information and blogs from around the web.  Check back frequently for updates.  If you don't see your favorite PostgreSQL blog linked, send me an email and I will add it.

Links to Visit 

PostgreSQL
The Official PostgreSQL Home Page.
PostgreSQL DB News
News and Commentary regarding the open source database, PostgreSQL.
EnterpriseDB News
News and Commentary regarding EnterpriseDB, the Oracle compatible database built from PostgreSQL.
EnterpriseDB Postgres Resource Center
EnterpriseDB Postgres Resource Center: Forums, Documentation, Support, Downloads
PostgreSQL Mail Lists
Postgres Related Mail Lists

Create a simple function in Postgres PL/pgSQL 

CREATE OR REPLACE FUNCTION func_1()
RETURNS CHAR VARYING(25)
AS $$
DECLARE
local_char_var CHAR(30);
BEGIN
SELECT datname
INTO local_char_var
FROM pg_database
LIMIT 1;

RETURN local_char_var;
END;
$$ LANGUAGE plpgsql;

Ok. Now we'll go through it line by line:

1. CREATE OR REPLACE FUNCTION func_1() - This line creates and names the function. The "OR REPLACE" will let us modify the function without fir DROPping it. func_1 can be any valid PLpgSQL name. Even if you are not declaring parameters, you must include the parenthesis ().

2. RETURNS CHAR VARYING(25) - RETURNS is the keyword that signifies what data type the function will be returing. RETURN is the equivalent in PL/SQL. Notice the S. CHAR VARYING is the equivalent of a VARCHAR2 in PL/SQL. In this case it will be a VARCHAR2(25).

3. AS $$ - AS is the same as the PL/SQL AS. The $$ is the function code delimiter. You can actually use single quotes here instead of $$ but in that case you would need to double all the quotes in your code. If that doesn't make sense, just consider the $$ mandatory. PLpgSQL is a more basic language than PL/SQL. The code is stored as text and compiled as it is run. The entire function body is just a string and the $$ is the delimiter.

Read the rest of this entry.

Call a Function in PL/pgSQL 

To call either a function, you can run:

SELECT func_1();

Or

SELECT * FROM func_1();

The PostgreSQL Blog Feed 

Blog Feeds From Around the Web

If you don't see your favorite blog here, send me a note and I will add it!

Loading Fetching RSS feed... please stand by

Postgres Comparisons 


  1. PostgreSQL vs Firebird, August 2007 (and hopefully it will remain updated)

  2. PostgreSQL vs. SQL Server: PostgreSQL is right for the Microsoft stack, SearchEntepriseLinux May 15, 2006

  3. PostgreSQL vs. Oracle: Users speak out, SeachOracle April 6, 2006

  4. Oracle 10g vs PostgreSQL 8 vs MySQL 5, This one I wrote, Aug 22, 2005

  5. MySQL vs. PostgreSQL, Aug 9, 2005

  6. PostgreSQL vs MySQL with Rails, June 18, 2005

  7. PostgreSQL or MySQL - Feb 15 2005, a fairly nice comparison actually.

  8. PostgreSQL vs. MySQL vs. Commercial Databases: It's All About What You Need - DevX April 12, 2004

  9. PostgreSQL vs MySQL: Which is better?, DatabaseJournal Dec 16, 2003

  10. Firebird vs Postgres, Forum Post, April 23, 2002

  11. PostgreSQL vs. MySQL (Web Techniques, Sep 2001), Dr Dobbs, Jan 1, 2002

PostgreSQL Plexo 

Which is the BEST PostgreSQL book?

Vote UP for your favorite or vote DOWN the one you hate! Add your own, too!

PostgreSQL (2nd Edition) (Developer's Library) by Korry Douglas

PostgreSQL (2nd Edition) (Developer's Library) by Korry Douglas

This is my favorite PostgreSQL book. It's good fo more...1 point

Beginning PHP and PostgreSQL 8: From Novice to Professional by W. Jason Gilmore

Beginning PHP and PostgreSQL 8: From Novice to Professional by W. Jason Gilmore

This is probably my second favorite postgres book. more...1 point

Beginning Databases with PostgreSQL: From Novice to Professional, Second Edition (Beginning from Novice to Professional) by Neil Matthew

Beginning Databases with PostgreSQL: From Novice to Professional, Second Edition (Beginning from Novice to Professional) by Neil Matthew

Another good book but not as in depth as some othe more...0 points

PostgreSQL: Introduction and Concepts by Bruce Momjian

PostgreSQL: Introduction and Concepts by Bruce Momjian

A classic but somewhat dated now.0 points

PostgreSQL and OSD News 

Loading Fetching RSS feed... please stand by

Alternate Source for PostgreSQL Books 

A First Course in Database Systems

A First Course in Database Systems

Price: $91.00

Written by well-known computer scientists, this accessible and succinct introduction to database systems focuses on database design and use. Provides... more »

Database Administration

Database Administration

Price: $49.99

A thorough reference on database administration outlines a variety of DBA roles and responsibilities and discusses such topics as data modeling and no... more »

Inside Relational Databases

Inside Relational Databases

Price: $39.95

A good starter guide to databases.

Data Access Patterns

Data Access Patterns

Price: $54.99

25 proven patterns for improving data access and application performance Efficient, high-quality data access code is crucial to the performance and... more »

SQL Demystified

SQL Demystified

Price: $19.95

There s no easier, faster, or more practical way to learn the really tough subjects SQL Demystified explains how to use SQL (Structured Query Langua... more »

Beginning Databases With Postgresql

Beginning Databases With Postgresql

Price: $44.99

A good beginner book. Plenty of beginners info and a decent reference once you get some experience.

Practical Postgresql

Practical Postgresql

Price: $44.95

A classic reference.

Postgresql Essential Reference

Postgresql Essential Reference

Price: $39.99

Description not available. Copyright (C) Muze Inc. 2005. For personal use only. All rights reserved.

The Database Hacker's Handbook

The Database Hacker's Handbook

Price: $50.00

Description not available. Copyright (C) Muze Inc. 2005. For personal use only. All rights reserved.

New Guestbook 

Like this lens? Want to share your feedback, or just give a thumbs up? Be the first to submit a blurb!

X
lewisc

About lewisc

Lewis Cunningham is an Author, Blogger and Database Architect.  He has worked in the Finance, Military, Airline Travel, Higher Education, Software and Consulting indutries.

Lewis is an Oracle ACE, a 9i Certified PL/SQL Developer and a member of ODTUG, IOUG, ACM and FWA.

Lewis has many varied interests including writing, cooking, getting healthy and, his favorite past-time, spending time with the family.

lewisc's Pages

See all of lewisc's pages