kuniku’s diary

はてなダイアリーから移行(旧 d.hatena.ne.jp/kuniku/)、表示がおかしな箇所はコメントをお願いします。記載されている内容は日付およびバージョンに注意してください。直近1年以上前は古い情報の可能性が高くなります。

to_timestampでのキャストエラー

  • Insert 文でtimestamp のキャストでエラーになる。


ERROR: function to_timestamp(timestamp without time zone, unknown) does not exist at character 73
HINT: No function matches the given name and argument types. You might need to add explicit type casts.

http://lets.postgresql.jp/documents/tutorial/cast/
http://www.adempiere.com/PostgreSQL_8.3_issues

http://nobuneko.com/blog/archives/2010/05/postgresql83operator_does_not.html

8.3から、変わった模様。
もちろん、2014-10-24時点の最新である9.3でも発生する。

以下のように、 functionを作成すると、アプリ側を修正しなくてもいける。


CREATE FUNCTION pg_catalog.text(timestamp without time zone) RETURNS text STRICT STABLE LANGUAGE SQL AS 'SELECT textin(timestamp_out($1));';
CREATE CAST (timestamp without time zone AS text) WITH FUNCTION pg_catalog.text(timestamp without time zone) AS IMPLICIT;