Shvalb
Shvalb

Reputation: 1933

What's the equivalent to Oracle Packages in PostgreSQL

I'm pretty new to PostgreSQL and I wonder if such a thing exists...

I saw some discussions, but nothing concrete..

Thanks!

Upvotes: 21

Views: 26176

Answers (3)

Some
Some

Reputation: 514

As written before postgresql has no packages.

Example with namespace. It can be placed in single sql file.

Other methods can be added similarly.

--drop function if exists pack_exmpl.get_name(bigint);
--drop function if exists pack_exmpl.get_abbr(bigint);    
--drop schema if exists pack_exmpl;

drop schema if exists pack_exmpl cascade;
create schema pack_exmpl;

create or replace function pack_exmpl.get_name(p_id bigint)
returns varchar as $$
declare
  l_retval varchar;
begin
   select name into l_retval from example_table where id = p_id;
   return l_retval;
end;
$$ language plpgsql IMMUTABLE;

create or replace function pack_exmpl.get_abbr(p_id bigint)
returns varchar as $$
declare
  l_retval varchar;
begin
  select abbr into l_retval from example_table where id = p_id;
  return l_retval;
end;
$$ language plpgsql IMMUTABLE;

Upvotes: 2

user330315
user330315

Reputation:

No, there is no equivalent.

The only remotely similar thing would be to create one schema for each "package" and put all functions of one package into that schema. That way you have at least something like the namespace that packages give you.

This of course does not give you package private functions or package wide variables at all.

Upvotes: 18

Related Questions