Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support of "DEFAULT" mysql data type #1821

Closed
sscots opened this issue Sep 13, 2017 · 4 comments
Closed

Support of "DEFAULT" mysql data type #1821

sscots opened this issue Sep 13, 2017 · 4 comments
Assignees
Labels

Comments

@sscots
Copy link

sscots commented Sep 13, 2017

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'])

@dougwilson
Copy link
Member

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?

@dougwilson
Copy link
Member

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.

@dougwilson
Copy link
Member

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.

@dougwilson
Copy link
Member

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'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants