storage icon indicating copy to clipboard operation
storage copied to clipboard

Bug with SQL queries

Open Arputikos opened this issue 1 year ago • 0 comments

This is my stackoverflow question: https://stackoverflow.com/questions/79067775/sql-select-statement-returning-different-values-when-columns-in-different-order

but investigating this I found that it apparently is a bug because when changed vercel postgresql package to pg, the same query works.

Full problem:

I have a very weird SQL problem. I am creating next.js project and using vercel postgres sql. So when I call

const result = await sqlSELECT isenabled FROM Chatbots WHERE id = ${chatbotId};; It returns { isenabled: true } as expected. When I do

SELECT isenabled, cssbubblestyles FROM Chatbots WHERE id = ${chatbotId}; it returns...

{ isenabled: true, cssbubblestyles: '' } And that's incorrect, because in vercel I clearly see it has value. Also in pgAdmin 4.

When I do:

SELECT isenabled, cssbubblestyles, internalname FROM Chatbots WHERE id = ${chatbotId}; It returns correctly:

{  isenabled: true,  cssbubblestyles: '#chatbot-launcher { background-color: #aaabbb; }',

internalname: 'Chatbot' }

Why on earth calling it with just isenabled and cssbubblestyles returns only the first value and null?

What's the best part - when I change the order to cssbubblestyles, isenabled, it returns correct values... Also, when I write just CSSBubbleStyles, or isenAbled, instead of lower case, it also works.

Any ideas?

Working code with pg library:

const result = await pool.query<ChatbotBubbleData>( SELECT isenabled, cssbubblestyles FROM Chatbots WHERE id = $1, [chatbotId] );

Arputikos avatar Oct 08 '24 21:10 Arputikos