Skip to content

Instantly share code, notes, and snippets.

@matchy256
Created June 24, 2015 00:56
Show Gist options
  • Save matchy256/36044648d33b72e92141 to your computer and use it in GitHub Desktop.
Save matchy256/36044648d33b72e92141 to your computer and use it in GitHub Desktop.
古いPostgreSQLから移設したデータベースでキャストエラーが出るとき
-- for PostgreSQL 8.2
CREATE FUNCTION int4text(int4) RETURNS text AS 'SELECT textin(int4out($1))' LANGUAGE sql IMMUTABLE STRICT;
CREATE CAST (int4 AS text) WITH FUNCTION int4text(int4) AS IMPLICIT;
CREATE FUNCTION int8text(int8) RETURNS text AS 'SELECT textin(int8out($1))' LANGUAGE sql IMMUTABLE STRICT;
CREATE CAST (int8 AS text) WITH FUNCTION int8text(int8) AS IMPLICIT;
-- for PostgreSQL 8.4 or later
CREATE CAST (int4 AS text) WITH INOUT AS IMPLICIT;
CREATE CAST (int8 AS text) WITH INOUT AS IMPLICIT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment