0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PostgreSqlにてencode関数を利用したいのに、encode(text, unknown) does not exist とかになっちゃう件

Posted at

下記テーブルを例にして記載します。

create table sampletable (
    name  text,
    birthday date
);

下記に様にすると取れそうですがエラーが発生します。

SELECT name, birthday, 
ENCODE( CONCAT( '{"name":"', name, '","birthday":"', CAST(birthday AS varchar), '"}'), 'base64') AS jsondata
FROM sampletable;
// 下記エラーが発生する
function encode(text, unknown) does not exist

バイナリ型に変換する必要があり、「::bytea」を付ける必要があります。

SELECT name, birthday, 
ENCODE( CONCAT( '{"name":"', name, '","birthday":"', CAST(birthday AS varchar), '"}')::bytea , 'base64') AS jsondata
FROM sampletable;

これで勝つる!

参考にしたサイト
PostgreSQLのテキスト型にBASE64文字列を入れて使うなら便利なこと | Exfield

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?