1

I’m trying to create a SQL-procedure spAppeUpdatetTimes() using SQL which accepts a string argument of the UPC item on the input. But it does not work correctly. At the output, it occurs that the procedure takes as an input not a solid string but several arguments. It is because the UPC value of the item becomes splited (divided) into individual characters. What should I do to avoid this bug?

CREATE OR REPLACE FUNCTION external.spAppeUpdatetTimes(
upc character varying)

  RETURNS void
  LANGUAGE 'sql'

  COST 100
  VOLATILE 
AS $BODY$

    update external."tbProducts" as pu
            set "eBayDiscontinued"= current_timestamp
    from external."tbProducts" as ps 
    where pu."eBayUPC"=upc;
    end;

  $BODY$;

  ALTER FUNCTION external.spappeupdatettimes(character varying)
       OWNER TO postgreadmin;

Calling the procedure in Python:

 cursor.callproc('external."spAppeUpdatetTimes"', (record[2]))

The table that contains data:

CREATE TABLE external."tbProducts"
("UPC" character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT "tbProducts_pkey" PRIMARY KEY ("CWRPartNumber"))

However, when I try to use the function, I get the following error:

ProgrammingError('function external.spAppeUpdatetTimes(unknown, 
unknown, unknown, unknown, unknown, unknown) does not exist\nLINE 1: 
SELECT * FROM external."spAppeUpdatetTimes" 
 (\'1\',\'9\',\'3\',\'0\',...\n                      ^\nHINT:  No 
  function matches the given name and argument types. You might need 
  to add explicit type casts.
4
  • The problem is solved. When doing a procedure call in python code, the arguments 'callproc' must be tuple or list. mysqltutorial.org/calling-mysql-stored-procedures-python Commented Aug 10, 2018 at 11:01
  • Please answer your own question with the correct example. Commented Aug 10, 2018 at 21:44
  • cursor.callproc('external."spAppeUpdatetTimes"', (record[2], )) Commented Aug 11, 2018 at 20:27
  • You should have a button titled something like 'Answer your own question'. Commented Aug 12, 2018 at 0:09

2 Answers 2

1

The problem is solved. When doing a procedure call in python code, the arguments 'callproc' must be tuple or list. mysqltutorial.org/calling-mysql-stored-procedures-python.

cursor.callproc('external."spAppeUpdatetTimes"', (record[2], ))

Sign up to request clarification or add additional context in comments.

Comments

0

Try explicitly joining the data.

Something like

cursor.callproc('external."spAppeUpdatetTimes"', ''.join((record[2])))

1 Comment

Set the data type of the text in the function, but nothing changes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.