Reputation: 1933
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
Reputation: 11
I would point out that the EnterpriseDB version of Postgres supports Oracle Packages.
https://www.enterprisedb.com/products/edb-postgres-advanced-server-secure-ha-oracle-compatible
Upvotes: 1
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
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