1998-06-16 15:07:11 +08:00
|
|
|
--
|
|
|
|
-- PostgreSQL code for LargeObjects
|
|
|
|
--
|
2003-11-30 06:41:33 +08:00
|
|
|
-- $PostgreSQL: pgsql/contrib/lo/lo.sql.in,v 1.11 2003/11/29 22:39:22 pgsql Exp $
|
1998-06-16 15:07:11 +08:00
|
|
|
--
|
|
|
|
--
|
|
|
|
-- Create the data type
|
|
|
|
--
|
|
|
|
|
|
|
|
-- used by the lo type, it takes an oid and returns an lo object
|
2002-10-19 02:41:22 +08:00
|
|
|
|
|
|
|
-- Adjust this setting to control where the objects get created.
|
|
|
|
SET search_path = public;
|
|
|
|
|
|
|
|
CREATE FUNCTION lo_in(cstring)
|
|
|
|
RETURNS lo
|
|
|
|
AS 'MODULE_PATHNAME'
|
2002-12-31 18:22:03 +08:00
|
|
|
LANGUAGE 'C' IMMUTABLE;
|
1998-06-16 15:07:11 +08:00
|
|
|
|
|
|
|
-- used by the lo type, it returns the oid of the object
|
2002-10-19 02:41:22 +08:00
|
|
|
CREATE FUNCTION lo_out(lo)
|
|
|
|
RETURNS cstring
|
|
|
|
AS 'MODULE_PATHNAME'
|
2002-12-31 18:22:03 +08:00
|
|
|
LANGUAGE 'C' IMMUTABLE;
|
1998-06-16 15:07:11 +08:00
|
|
|
|
|
|
|
-- finally the type itself
|
2002-10-19 02:41:22 +08:00
|
|
|
CREATE TYPE lo (
|
|
|
|
INTERNALLENGTH = 4,
|
|
|
|
EXTERNALLENGTH = variable,
|
|
|
|
INPUT = lo_in,
|
|
|
|
OUTPUT = lo_out
|
1998-06-16 15:07:11 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- this returns the oid associated with a lo object
|
2002-10-19 02:41:22 +08:00
|
|
|
CREATE FUNCTION lo_oid(lo)
|
|
|
|
RETURNS oid
|
|
|
|
AS 'MODULE_PATHNAME'
|
2002-12-31 18:22:03 +08:00
|
|
|
LANGUAGE 'C' IMMUTABLE;
|
1998-06-16 15:07:11 +08:00
|
|
|
|
2000-11-22 05:51:58 +08:00
|
|
|
-- same function, named to allow it to be used as a type coercion, eg:
|
2002-10-19 02:41:22 +08:00
|
|
|
-- CREATE TABLE a (image lo);
|
|
|
|
-- SELECT image::oid FROM a;
|
2000-11-22 05:51:58 +08:00
|
|
|
--
|
2002-10-19 02:41:22 +08:00
|
|
|
CREATE FUNCTION oid(lo)
|
|
|
|
RETURNS oid
|
|
|
|
AS 'MODULE_PATHNAME', 'lo_oid'
|
2002-12-31 18:22:03 +08:00
|
|
|
LANGUAGE 'C' IMMUTABLE;
|
|
|
|
CREATE CAST (lo as oid) WITH FUNCTION oid(lo) AS IMPLICIT;
|
2000-11-22 05:51:58 +08:00
|
|
|
|
1998-06-16 15:07:11 +08:00
|
|
|
-- this allows us to convert an oid to a managed lo object
|
|
|
|
-- ie: insert into test values (lo_import('/fullpath/file')::lo);
|
2002-10-19 02:41:22 +08:00
|
|
|
CREATE FUNCTION lo(oid)
|
|
|
|
RETURNS lo
|
|
|
|
AS 'MODULE_PATHNAME'
|
2002-12-31 18:22:03 +08:00
|
|
|
LANGUAGE 'C' IMMUTABLE;
|
|
|
|
CREATE CAST (oid as lo) WITH FUNCTION lo(oid) AS IMPLICIT;
|
1998-06-16 15:07:11 +08:00
|
|
|
|
|
|
|
-- This is used in triggers
|
2002-10-19 02:41:22 +08:00
|
|
|
CREATE FUNCTION lo_manage()
|
|
|
|
RETURNS trigger
|
|
|
|
AS 'MODULE_PATHNAME'
|
|
|
|
LANGUAGE 'C';
|