1

I am new to python and I can't seem to figure out why I am getting this error. It is telling me I have too many parameters however the table has 8 columns, and I pass it 8 parameters. What is going on? Could this error be misleading and the real problem is the fact that I am trying to pass in values that could be None or could be of type Boolean using %s?

Here is the code snippet

        db.cursor().execute("CREATE TABLE temp_clean_mp_duplicates (id bigint, distinctid character varying(255), created timestamp without time zone, email character varying(255), created_exist boolean, email_exist boolean, user_exist boolean, distinct_id_found boolean, CONSTRAINT temp_clean_mp_duplicates_pkey PRIMARY KEY(id));")

        mp_email = None
        email_exist = False
        if "$email" in mp_properties :
            mp_email = mp_properties["$email"]
            email_exist = True

        mp_distinct_id = result["$distinct_id"]
        db_cursor.execute("SELECT u.id, u.email, udm.distinctid, u.sessionId FROM users as u,user_distinctid_map as udm where u.id = udm.user_id and udm.distinctid = %s and lower(email) = lower(%s)", (mp_distinct_id,mp_email,))
        distinct_id_found = True
        if db_cursor.rowcount == 0 :
            distinct_id_found = False

        created = None
        created_exist = False
        if "$created" in mp_properties :
            created = mp_properties["$created"]
            created_exist = True



            db_cursor.execute("SELECT u.id, u.email, u.sessionId FROM users as u where lower(u.email) = lower(%s)", (mp_email,))
            user_id = 0
            user_exist = False
            if db_cursor.rowcount > 0 :
                user_id = db_cursor.fetchone()[0]
                user_exist = True

            db.cursor().execute("INSERT INTO temp_clean_mp_duplicates (id, distinctid, created, email) VALUES (%s,%s,%s,%s,%s,%s,%s,%s);", (user_id, mp_distinct_id, created, mp_email, created_exist, email_exist, user_exist, distinct_id_found))

1 Answer 1

4

As you found, the issue is indeed the INSERT statement:

INSERT INTO temp_clean_mp_duplicates (id, distinctid, created, email) VALUES (%s,%s,%s,%s,%s,%s,%s,%s);", (user_id, mp_distinct_id, created, mp_email, created_exist, email_exist, user_exist, distinct_id_found)

You're right that the table has eight columns, but you're telling SQL that you're only setting four of them with INSERT INTO temp_clean_mp_duplicates (id, distinctid, created, email) - the columns in the parenthesis are the ones that it will try to set.

Here's how I think of an INSERT statement:

INSERT INTO <tablename> (<target columns>) VALUES (<values on new row>)

So if you're trying to set all eight of them, you would need to put all the column names in the parenthesis:

INSERT INTO temp_clean_mp_duplicates (id, distinctid, created, email, created_exist, email_exist, user_exist, distinct_id_found) VALUES (%s,%s,%s,%s,%s,%s,%s,%s);", (user_id, mp_distinct_id, created, mp_email, created_exist, email_exist, user_exist, distinct_id_found)

The above query should work.

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

Comments

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.