From: | "Jean-Yves F(dot) Barbier" <12ukwn(at)gmail(dot)com> |
---|---|
To: | rterry(at)pacific(dot)net(dot)au |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: bytea and text |
Date: | 2009-11-28 00:08:31 |
Message-ID: | 4B1069FF.70508@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
richard terry a écrit :
...
> tom, I wonder if you could give us a sample of using client side lo_creat ,
> insert functions to insert a blob into postgres - in an sql statement.
>
> Despite reading the docs's I'm totally in the dark and can't understand the
> syntax.
Hi Richard, I modified the functions I sent you: they now store into
BINARY (BYTEA) format, not anymore into BASE64:
CREATE OR REPLACE FUNCTION ucommon.testbytea_ins(Pstring TEXT) RETURNS oid AS $$
DECLARE
NewId OID;
NewBytea BYTEA;
BEGIN
NewBytea = decode(Pstring, 'base64');
INSERT INTO common.testbytea VALUES(default, NewBytea);
SELECT id INTO NewId FROM common.testbytea WHERE id = (SELECT currval('testbytea_id_seq'));
RETURN NewId;
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;
REVOKE ALL ON FUNCTION ucommon.testbytea_ins(TEXT) FROM PUBLIC;
---------------------------------------------------
CREATE OR REPLACE FUNCTION ucommon.testbytea_sel(Pid OID) RETURNS TEXT AS $$
DECLARE
MyPic BYTEA;
MyString TEXT;
BEGIN
SELECT pic INTO MyPic FROM common.testbytea WHERE id = Pid;
MyString = encode(MyPic, 'base64');
RETURN MyString;
END;
$$ LANGUAGE PLPGSQL STRICT SECURITY DEFINER;
REVOKE ALL ON FUNCTION ucommon.testbytea_sel(OID) FROM PUBLIC;
HIWH
JY
--
Objects in mirror may be closer than they appear.
From | Date | Subject | |
---|---|---|---|
Next Message | Syan Tan | 2009-11-28 01:05:12 | Re: bytea and text |
Previous Message | Syan Tan | 2009-11-28 00:00:06 | Re: bytea and text |