1998-06-16 15:07:11 +08:00
|
|
|
--
|
|
|
|
-- PostgreSQL code for LargeObjects
|
|
|
|
--
|
2005-01-30 06:35:02 +08:00
|
|
|
-- $PostgreSQL: pgsql/contrib/lo/lo.sql.in,v 1.12 2005/01/29 22:35:02 tgl 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'
|
2005-01-30 06:35:02 +08:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
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'
|
2005-01-30 06:35:02 +08:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
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'
|
2005-01-30 06:35:02 +08:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
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'
|
2005-01-30 06:35:02 +08:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2002-12-31 18:22:03 +08:00
|
|
|
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'
|
2005-01-30 06:35:02 +08:00
|
|
|
LANGUAGE C IMMUTABLE STRICT;
|
2002-12-31 18:22:03 +08:00
|
|
|
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'
|
2005-01-30 06:35:02 +08:00
|
|
|
LANGUAGE C;
|