0

I have a function created as follows:

CREATE LANGUAGE plpythonu;

CREATE OR REPLACE FUNCTION unpickle (data text)
    RETURNS text[]
AS $$
    import base64
    import pickle

    return pickle.loads(base64.b64decode(data))
$$ LANGUAGE plpythonu IMMUTABLE;

CREATE INDEX issues_unpickle_tags_index ON issue USING btree (unpickle(tags));

I am getting an error when creating the index as - ERROR: function unpickle(text[]) does not exist.

The structure of table is like this:

CREATE TABLE "issue" (
  "id" int4 DEFAULT nextval('issue_id_seq'::regclass) NOT NULL,
  "tags" text[] COLLATE "default",
  "description" text COLLATE "default" NOT NULL
)

I tried changing the first part to

CREATE OR REPLACE FUNCTION unpickle (data text[])
    RETURNS text[]

Then get the error - ERROR: TypeError: must be string or buffer, not list

What am I doing wrong here.

Andreas
  • 4,937
  • 2
  • 25
  • 35
jethar
  • 2,223
  • 2
  • 22
  • 19
  • I believe you need to use a GIN index for array types. – John Powell Aug 04 '14 at 17:48
  • 2
    Both errors are obvious. The first is that the function is expecting a text and you are passing a text array. The second is that `b64decode` is expecting a string and you are passing a list of strings. Now what is really important is what are you trying to do?!!! Saving pickled data in an array? It does not make sense. – Clodoaldo Neto Aug 04 '14 at 17:49
  • Clodoaldo Neto : if I want to just have the index created without error, what do I need to do. This is a open-source project on github with not much documentation, i am trying to debug. So any help appreciated. – jethar Aug 04 '14 at 18:06
  • @nobuzz _to just have the index created without error_ you must pass the function a parameter of the type it is expecting, and it is expecting text, not a text array which is the type of `tags`. Why do you think that the `tags` text array is pickled? Post the function that saves data to the `issue` table. – Clodoaldo Neto Aug 05 '14 at 12:47

0 Answers0