#postgres, asyncpg, DatatypeMismatchError argument of AND must be type boolean, not type bigint

32 messages · Page 1 of 1 (latest)

next juniper
#
INSERT INTO twitch_config (guild, channel, username, message) VALUES ($1, $2, $3, $4)
ON CONFLICT (guild) DO UPDATE SET channel = $2 AND username = $3 AND message = $4 WHERE twitch_config.guild = $1
next cloak
#

The value you're inserting is the issue. The query isn't the issue.

#

Hmm

next juniper
#

i mean they should be right, lemme check the types

next cloak
#

I think it's upset about channel = $2

next juniper
#

i dont see how

#
<class 'discord.channel.TextChannel'> # channel
<class 'str'> # username
<class 'str'> # message
#
    (
        guild BIGINT PRIMARY KEY,
        channel BIGINT NOT NULL,
        username TEXT NOT NULL,
        message TEXT NOT NULL
    )
``` this is my table, nothings wrong with this right?
next cloak
#

It's talking about the AND

#

So it is an issue with the query syntax. Put channel = $2 in parentheses

next juniper
#

alr

#

shall i do that with the other ones?

#

asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "="

next cloak
#

What did you change the query to

next juniper
#
INSERT INTO twitch_config (guild, channel, username, message) VALUES ($1, $2, $3, $4)
ON CONFLICT (guild) DO UPDATE SET (channel = $2) AND username = $3 AND message = $4 WHERE twitch_config.guild = $1
next cloak
#

Get rid of the spaces around the =

next juniper
#

for all of them?

#

still dosent work

#

very weird

#

im pretty sure ive had this issue before

#

2 mins

#

#831374198432989194 message

next cloak
#

Wait, put parentheses around the entire condition.

DO UPDATE SET (Channel = $2 AND username = $3 AND message $4 WHERE twitch_config.guild = $1)
next juniper
#

alr

next juniper
#

: asyncpg.exceptions.PostgresSyntaxError: syntax error at or near "="

next cloak
#

Oh yeah this is a set not a condition. You can't use AND outside of a condition or boolean logic. Use commas when setting.

next juniper
#

ah, i didnt know that

next cloak
#

You're giving it a list of column values.

#

You're not checking column values

next juniper
#

i should probably learn sql outside of making my bot, would help me know things like that lmao