I'm pretty new to PostgreSQL and I wonder if such a thing exists...
I saw some discussions, but nothing concrete..
Thanks!
Postgres does not have packages, but, using schema architecture, functions and procedures can be grouped. Use the “orafce” migration tool library, which supports some of the standard packages, or EDB Postgres Advanced Server, which has built-in Packages.
In PostgreSQL, use type varchar or text instead. Similarly, replace type number with numeric , or use some other numeric data type if there's a more appropriate one. Instead of packages, use schemas to organize your functions into groups. Since there are no packages, there are no package-level variables either.
PostgreSQL is by no means a drop-in replacement for Oracle's database, but a developer or DBA that is familiar with Oracle will find PostgreSQL similar.
PostgreSQL is an open source object-relational database management system. It's highly extensible, highly scalable, and has many features. PostgreSQL supports data replication across multiple data centers.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With