Re: cast lo to oid - Mailing list pgsql-sql

From Tom Lane
Subject Re: cast lo to oid
Date
Msg-id 19382.1036682181@sss.pgh.pa.us
Whole thread Raw
In response to cast lo to oid  ("Nekta Katz" <nekta_k@hotmail.com>)
List pgsql-sql
"Nekta Katz" <nekta_k@hotmail.com> writes:
> I have the following table

> create table scan_docs (
>     docid   serial,
>     shipno numeric(10),
>     scan    lo,
>     type text
> );

> when I try to create the following rule

> create rule "delete_scan_docs_lo" as
> on delete to "scan_docs"
> do select lo_unlink (old.scan);

Why aren't you using the trigger that type LO provides for this purpose?
Seems rather pointless to use a nonstandard type and then ignore the
primary (sole) feature it provides...

> create rule "delete_scan_docs_lo" as
> on delete to "scan_docs"
> do select lo_unlink (old.scan::oid);

> "psql:scan_docs_rule.sql:3: ERROR:  Cannot cast type 'lo' to 'oid' "

Curious, as contrib/lo provides a function that's supposed to work
for that:

-- 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';

What PG version are you using?
        regards, tom lane


pgsql-sql by date:

Previous
From: Achilleus Mantzios
Date:
Subject: Re: how to get the source table & field name of a view field
Next
From: Christoph Haller
Date:
Subject: PLpgSQL FOR IN EXECUTE question