mirror of https://github.com/postgres/postgres
a physically separate type. Defining 'lo' as a domain over OID works just fine and is more efficient. Improve documentation and fix up the test script. (Would like to turn test script into a proper regression test, but right now its output is not constant because of numeric OIDs; plus it makes Unix-specific assumptions about files it can import.)REL8_1_STABLE
parent
d20763dbee
commit
5b0c9d3603
@ -1,62 +1,29 @@ |
||||
-- |
||||
-- PostgreSQL code for LargeObjects |
||||
-- PostgreSQL code for managed Large Objects |
||||
-- |
||||
-- $PostgreSQL: pgsql/contrib/lo/lo.sql.in,v 1.12 2005/01/29 22:35:02 tgl Exp $ |
||||
-- |
||||
-- |
||||
-- Create the data type |
||||
-- $PostgreSQL: pgsql/contrib/lo/lo.sql.in,v 1.13 2005/06/23 00:06:37 tgl Exp $ |
||||
-- |
||||
|
||||
-- used by the lo type, it takes an oid and returns an lo object |
||||
|
||||
-- Adjust this setting to control where the objects get created. |
||||
SET search_path = public; |
||||
|
||||
CREATE FUNCTION lo_in(cstring) |
||||
RETURNS lo |
||||
AS 'MODULE_PATHNAME' |
||||
LANGUAGE C IMMUTABLE STRICT; |
||||
|
||||
-- used by the lo type, it returns the oid of the object |
||||
CREATE FUNCTION lo_out(lo) |
||||
RETURNS cstring |
||||
AS 'MODULE_PATHNAME' |
||||
LANGUAGE C IMMUTABLE STRICT; |
||||
|
||||
-- finally the type itself |
||||
CREATE TYPE lo ( |
||||
INTERNALLENGTH = 4, |
||||
EXTERNALLENGTH = variable, |
||||
INPUT = lo_in, |
||||
OUTPUT = lo_out |
||||
); |
||||
|
||||
-- this returns the oid associated with a lo object |
||||
CREATE FUNCTION lo_oid(lo) |
||||
RETURNS oid |
||||
AS 'MODULE_PATHNAME' |
||||
LANGUAGE C IMMUTABLE STRICT; |
||||
-- |
||||
-- Create the data type ... now just a domain over OID |
||||
-- |
||||
|
||||
-- same function, named to allow it to be used as a type coercion, eg: |
||||
-- CREATE TABLE a (image lo); |
||||
-- SELECT image::oid FROM a; |
||||
-- |
||||
CREATE FUNCTION oid(lo) |
||||
RETURNS oid |
||||
AS 'MODULE_PATHNAME', 'lo_oid' |
||||
LANGUAGE C IMMUTABLE STRICT; |
||||
CREATE CAST (lo as oid) WITH FUNCTION oid(lo) AS IMPLICIT; |
||||
CREATE DOMAIN lo AS pg_catalog.oid; |
||||
|
||||
-- this allows us to convert an oid to a managed lo object |
||||
-- ie: insert into test values (lo_import('/fullpath/file')::lo); |
||||
CREATE FUNCTION lo(oid) |
||||
RETURNS lo |
||||
AS 'MODULE_PATHNAME' |
||||
LANGUAGE C IMMUTABLE STRICT; |
||||
CREATE CAST (oid as lo) WITH FUNCTION lo(oid) AS IMPLICIT; |
||||
-- |
||||
-- For backwards compatibility, define a function named lo_oid. |
||||
-- |
||||
-- The other functions that formerly existed are not needed because |
||||
-- the implicit casts between a domain and its underlying type handle them. |
||||
-- |
||||
CREATE FUNCTION lo_oid(lo) RETURNS pg_catalog.oid AS |
||||
'SELECT $1::pg_catalog.oid' LANGUAGE SQL STRICT IMMUTABLE; |
||||
|
||||
-- This is used in triggers |
||||
CREATE FUNCTION lo_manage() |
||||
RETURNS trigger |
||||
RETURNS pg_catalog.trigger |
||||
AS 'MODULE_PATHNAME' |
||||
LANGUAGE C; |
||||
|
||||
Loading…
Reference in new issue