invalid UTF-8 via pl/perl - Mailing list pgsql-hackers

From Hannu Krosing
Subject invalid UTF-8 via pl/perl
Date
Msg-id 1262470911.1813.16.camel@huvostro
Whole thread Raw
Responses Re: invalid UTF-8 via pl/perl  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
It is possible to get an invalid byte sequence into a text field via pl,
in this case pl/perl :

---8<------8<------8<------8<------8<------8<---
CREATE TABLE utf_test
( id serial PRIMARY KEY, data character varying
);

CREATE OR REPLACE FUNCTION invalid_utf_seq() RETURNS character varying AS
$BODY$
return "\xd0";
$BODY$
LANGUAGE 'plperlu' VOLATILE STRICT;

insert into utf_test(data) values(invalid_utf_seq());
---8<------8<------8<------8<------8<------8<---

This results in a table, which has invalid utf sequence in it and
consequently does not pass dump/load

What would be the best place to fix this ?

Should there be checks in all text types ? 
(probably too expensive)

Or should pl/perl check it's return values for compliance with
server_encoding ?

Or should postgresql itself check that pl-s return what they promise to
return ?


-- 
Hannu Krosing   http://www.2ndQuadrant.com
PostgreSQL Scalability and Availability   Services, Consulting and Training




pgsql-hackers by date:

Previous
From: David Fetter
Date:
Subject: Re: psql tab completion for DO blocks
Next
From: Tom Lane
Date:
Subject: Re: psql tab completion for DO blocks