Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
I believe you need to use a GIN index for array types. –  John Barça Aug 4 '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 4 '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. –  nobuzz Aug 4 '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 5 '14 at 12:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.