You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try to run the following query using the query() function, I get an error saying "DEFAULT" is not an int.
CREATE TABLE "test_table" ( "id" SERIAL NOT NULL PRIMARY KEY, "item" varchar(4) )
INSERT INTO "test_table" (id, item) VALUES (DEFAULT, '1234')
connection.query('INSERT INTO "test_table" (id, item) VALUES ($1, $2)', ['DEFAULT', '1234']) will throw the error.
Now I know I can just not specify "id" in the INSERT statement, but I have an exception to that sometimes where the value of "id" is a variable and the value of that variable is only sometimes the DEFAULT.
My current work around is connection.query('INSERT INTO "test_table" (id, item) VALUES (DEFAULT, $1)', ['1234'])
The text was updated successfully, but these errors were encountered:
I don't think this is an issue with this module. Using the mysql command line results in the same error. What client are you using in which that query works?
Ok, you editied your issue to be very different and my reply was based off what you originally wrote and was emailed to me. I'll need to look into what you have chabged it to.
Can you provide your full code? How are the $1 and $2 getting replaced? This library doesn't provide such functionality unless it's been modified in some way. But it sounds like whatever is doing that replacement is replacing $1 with 'DEFAULT' and not with DEFAULT.
I'm not sure if you edited the top post more after my responses or I mis-read (because there are not notifications when you edit posts), but I understand your issue now. A feature was just landed on master and will be released soon that will solve your problem: you'll use mysql.raw('DEFAULT') as the value to get the DEFAULT keyword to appear as-is.
Example:
connection.query('INSERT INTO "test_table" (id, item) VALUES (?, ?)',[mysql.raw('DEFAULT'),'1234'])
https://dev.mysql.com/doc/refman/5.7/en/data-type-defaults.html
When I try to run the following query using the query() function, I get an error saying "DEFAULT" is not an int.
CREATE TABLE "test_table" ( "id" SERIAL NOT NULL PRIMARY KEY, "item" varchar(4) )
INSERT INTO "test_table" (id, item) VALUES (DEFAULT, '1234')
connection.query('INSERT INTO "test_table" (id, item) VALUES ($1, $2)', ['DEFAULT', '1234'])
will throw the error.Now I know I can just not specify "id" in the INSERT statement, but I have an exception to that sometimes where the value of "id" is a variable and the value of that variable is only sometimes the DEFAULT.
My current work around is
connection.query('INSERT INTO "test_table" (id, item) VALUES (DEFAULT, $1)', ['1234'])
The text was updated successfully, but these errors were encountered: