What is wrong with my MYSQL Workbench Query? (Error Code: 1064) - mysql-workbench

I am getting an error code (1064) when I attempt to run a query in MYSQL Workbench. I have researched the error code and I'm aware that it is often thrown when a reserved keyword is used, a command is misspelled, or when using a depreciated command. I have checked my code and I don't see any of the aforementioned errors. I have made sure that the strings are all surrounded with quotation marks, the values and properties are in their corresponding positions, and that my sequelize model and datatypes are formatted appropriately. However, when I try to run the query, I get a red squiggly line under one entry (saying that the entry is not valid in it's position and that a ')' is expected) and the error code.
INSERT INTO drycleaningprices(sameDayService, delivery, pickUpFee, dryCleaningPrices1-14, addInfo, sameDayInfo, deliveryHours, pickUpHours, EstablishmentBusinessName)
VALUES (true, true,"$20.00",‍"kill","kill","kill","kill","kill","kill",‍"kill", "kill","kill",‍"kill","kill","kill",‍"kill","kill","kill","kill","kill","kill","Affordable Laundry")
I have even replaced each of the entries with duplicate strings to no avail. In the above code, "dryCleaningPrices1-14" is actually 14 separate entries but was shortened for readability. And here is my model:
module.exports = function(sequelize, DataTypes){
var DryCleaningPrices = sequelize.define("DryCleaningPrices",{
sameDayService:{
type: DataTypes.BOOLEAN,
defaultValue: false
},
delivery:{
type: DataTypes.BOOLEAN,
defaultValue: false
},
pickUpFee:{
type:DataTypes.STRING,
defaultValue: "Enter Info"
},
freePickUp:{
type: DataTypes.BOOLEAN,
defaultValue: false
},
deliveryOrderMinimum:{
type:DataTypes.STRING
},
dryCleaningPrices1-14:{
type:DataTypes.STRING
},
addInfo:{
type:DataTypes.TEXT
},
addInfo2:{
type:DataTypes.TEXT
},
addInfo3:{
type:DataTypes.TEXT
},
sameDayInfo:{
type:DataTypes.TEXT
},
deliveryHours:{
type:DataTypes.STRING
},
pickUpHours:{
type:DataTypes.STRING
},
createdAt:{
type:DataTypes.DATE
},
updatedAt:{
type:DataTypes.DATE
}
})
DryCleaningPrices.associate=function(models){
DryCleaningPrices.belongsTo(models.Establishment,{
foreignKey: {
allowNull: false
}
})
}
return DryCleaningPrices;
}
DDL:
Table Create Table
drycleaningprices CREATE TABLE `drycleaningprices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`sameDayService` tinyint(1) DEFAULT '0',
`delivery` tinyint(1) DEFAULT '0',
`pickUpFee` varchar(255) DEFAULT 'Enter Info',
`freePickUp` tinyint(1) DEFAULT '0',
`deliveryOrderMinimum` varchar(255) DEFAULT NULL,
`dryCleaningPrices1-14` varchar(255) DEFAULT NULL,
`addInfo` text,
`addInfo2` text,
`addInfo3` text,
`sameDayInfo` text,
`deliveryHours` varchar(255) DEFAULT NULL,
`pickUpHours` varchar(255) DEFAULT NULL,
`createdAt` datetime DEFAULT NULL,
`updatedAt` datetime DEFAULT NULL,
`EstablishmentBusinessName` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
KEY `EstablishmentBusinessName` (`EstablishmentBusinessName`),
CONSTRAINT `drycleaningprices_ibfk_1` FOREIGN KEY (`EstablishmentBusinessName`) REFERENCES `establishments` (`businessName`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

Your Insert statement is incorrect you have given 9 column names but in Values you have given more than 9. Ideally your insert statement should look like this
INSERT INTO test.drycleaningprices
(sameDayService, delivery, pickUpFee, `dryCleaningPrices1-14`, addInfo, sameDayInfo, deliveryHours, pickUpHours, EstablishmentBusinessName)
VALUES(true, true, "$20.00", "kill", "kill", "kill", "kill","kill", '');
Please refer
https://www.w3schools.com/sql/sql_insert.asp

Related

How to display a UUID in pg-promise without dashes

As per the stackoverflow question HERE postgres column does not store dashes for the UUID data type
Yet when I load the value of any UUID column using pg-promise it always shows dashes
How do I retrieve these UUIDs without dashes using pg-promise
Code sample illustrating the problem
var pgPromise = require("pg-promise"),
pgp = pgPromise({}),
db = pgp({
database: "mydatabase",
host: "localhost",
password: "somepass",
port: 5432,
ssl: false,
user: "myuser"
});
pgp.pg.types.setTypeParser(20, parseInt);
db.query("CREATE TABLE test(myid uuid not null primary key)")
.then((e => {
var r = require("crypto").createHash("md5").update("test data").digest("hex");
return db.query("INSERT INTO test(myid) VALUES($1) ON CONFLICT DO NOTHING", [r])
}))
.then((e => db.query("SELECT * FROM test")))
.then((e => (console.log(e), db.query("DROP TABLE test"))))
.then((() => console.log("test success!")))
.catch((e => console.error(e)));
This line did the trick
pgp.pg.types.setTypeParser(pgp.pg.types.builtins.UUID, (val) => {
val === null ? null : val.replace(/-/g, '')
});
Thank you for your suggestions #vitaly-t and #Bergi

How can I store Object data type in Postgres?

I have a kind of object like this:
{{generaladdendumlist: {}, microchip: null, freetext: null, additionalpermerchant: null, telephonecompany: null, passengertransportaddendumlist: {}, merchantinformation: {messagetypeidentifier: '1644', functioncode: '696', messagenumber: '53331800', formatcode: 'AA', forwardingreferencedata: '123456000000', cardacceptorbusinesscode: 5411, name: 'PROVE POS', street: 'VIA ROSSI 2', city: 'VERONA', postalcode: '000000', region: 'VR', countrycode: 'ITA'}, lodgingaddendumlist: {}, carrentaladdendumlist: {}, moneytransfer: null, fleetlist: {}, purchasinglist: {}, dccaddendum: null}}
I am retriving it from a Cassandra's table and processing it with Talend Big Data in order to fill my Postgres's table. How can I store it inside my table? I am trying text[] and character varying [], but the field remain empty.
Does anyone could help me, please?
Thank you in advance!

Sails.js one to many association with postgreSQL: column does not exist

I need some help with associations in sails 0.12.13 with postgresql.
I have an "App" model and a "Membership" model. Relation should be one to many (one app can be associated with many relationships).
This is the App model db table schema (table is called "apps"):
Table "public.apps"
Column | Type | Modifiers
------------+-----------------------------+---------------------------------------------------
id | integer | not null default nextval('apps_id_seq'::regclass)
name | character varying | not null
Indexes:
"apps_pkey" PRIMARY KEY, btree (id)
"apps_name_key" UNIQUE CONSTRAINT, btree (name)
Referenced by:
TABLE "memberships" CONSTRAINT "app_fk" FOREIGN KEY (app_id) REFERENCES apps(id) ON UPDATE RESTRICT ON DELETE CASCADE
And this is memberships:
Table "public.memberships"
Column | Type | Modifiers
------------+-----------------------------+----------------------------------------------------------
id | integer | not null default nextval('memberships_id_seq'::regclass)
app_id | integer | not null
Foreign-key constraints:
"app_fk" FOREIGN KEY (app_id) REFERENCES apps(id) ON UPDATE RESTRICT ON DELETE CASCADE
in my user model, i have this:
module.exports = {
tableName: 'apps',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
name: { type: 'string', unique: true, required: true, alphanumericdashed: true },
memberships: { collection: 'memberships', model: 'Membership' },
}
}
And this is the Membership model:
module.exports = {
tableName: 'memberships',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
app: { model: 'app', columnName: 'app_id' },
},
};
When I try to query an app and get its memberships:
App.find({ id: 1 }).populate('memberships').exec((err, app) => {
if (err) throw err;
console.log(app.memberships);
});
I get this error:
Error (E_UNKNOWN) :: Encountered an unexpected error
error: column apps.memberships does not exist
at Connection.parseE (/usr/src/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:539:11)
at Connection.parseMessage (/usr/src/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:366:17)
at Socket.<anonymous> (/usr/src/app/node_modules/sails-postgresql/node_modules/pg/lib/connection.js:105:22)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at addChunk (_stream_readable.js:252:12)
at readableAddChunk (_stream_readable.js:239:11)
at Socket.Readable.push (_stream_readable.js:197:10)
at TCP.onread (net.js:589:20)
Looks like the association is not "enabled" and waterline is searching for an actual column "membership" in my model. Can anybody explain me what I am doing wrong? thx
According to the documentation, I would guess that you have a bad association.
// App.js
module.exports = {
tableName: 'apps',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
name: {
type: 'string',
unique: true,
required: true,
alphanumericdashed: true
},
memberships: {
collection: 'membership', // <-- changed to singular (as your model should be)
via: 'app' // <-- use "via" instead of "model"
},
}
}
// Membership.js
module.exports = {
tableName: 'memberships',
autoCreatedAt: false,
autoUpdatedAt: false,
attributes: {
app: {
model: 'app'
// <-- removed the "columnName" here
},
},
};
Also, convention generally says name your model as a singular instance. For example, its "User.js" and not "Users.js". It's valid to refer to the collection as a plural. I made some changes in your naming, but you'll have to see how that affects your files (since you didn't give those names).

Doctrine2 ManyToMany relation using PostgreSQL: "SQLSTATE[42P01]: Undefined table: 7 ERROR: the relation does not exist"

When I make an INNER JOIN between two entities (connected by a ManyToMany relationship) doctrine says that cannot find the relation machine_table_for_base_model: SQLSTATE[42P01]: Undefined table: 7 ERROR: the relation "machine_table_for_base_model" does not exist. Why this happens?
I have an associative table defined as follows:
<!-- language: lang-sql -->
CREATE TABLE machine_table_for_base_model (
id_machine_table integer NOT NULL,
id_base_model integer NOT NULL,
);
ALTER TABLE ONLY machine_table_for_base_model
ADD CONSTRAINT machine_table_for_base_model_pkey PRIMARY KEY (id_machine_table, id_base_model);
ALTER TABLE ONLY machine_table_for_base_model
ADD CONSTRAINT machine_table_for_base_model_ibfk_1 FOREIGN KEY (id_machine_table) REFERENCES machine_table(id) ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE ONLY machine_table_for_base_model
ADD CONSTRAINT machine_table_for_base_model_ibfk_2 FOREIGN KEY (id_base_model) REFERENCES base_model(id) ON UPDATE CASCADE DEFERRABLE INITIALLY DEFERRED;
When I execute a doctrine mapping of the associated tables I have something like that:
Package\MyBundle\Entity\MachineTable:
type: entity
schema: techguide
table: machine_table
indexes:
IDX_8386B61E3C5569AA:
columns:
- edit_user
id:
id:
type: integer
nullable: false
options:
unsigned: false
id: true
generator:
strategy: SEQUENCE
fields:
description:
type: string
nullable: false
length: 200
options:
fixed: false
labelsDimensions:
type: text
nullable: false
length: null
options:
fixed: false
column: labels_dimensions
editDate:
type: datetime
nullable: false
options:
default: now
column: edit_date
manyToOne:
editUser:
targetEntity: Package\SupportBundle\Entity\Account
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: null
joinColumns:
edit_user:
referencedColumnName: id
orphanRemoval: false
manyToMany:
idBaseModel:
targetEntity: BaseModel
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: idMachineTable
joinTable:
name: machine_table_for_base_model
joinColumns:
-
name: id_machine_table
referencedColumnName: id
inverseJoinColumns:
-
name: id_base_model
referencedColumnName: id
orderBy: null
lifecycleCallbacks: { }
At last I found a solution to this problem. You need to edit (manually) the joinTable name on the ORM configuration, which in my case is a Yaml file, adding the Postgres schema the associative table belongs to:
Entity.orm.yml
manyToMany:
idBaseModel:
targetEntity: BaseModel
cascade: { }
fetch: LAZY
mappedBy: null
inversedBy: idMachineTable
joinTable:
name: <NAME_OF_YOUR_SCHEMA>.<NAME_OF_THE_TABLE>
joinColumns:
-
name: id_machine_table
referencedColumnName: id
inverseJoinColumns:
-
name: id_base_model
referencedColumnName: id
orderBy: null
lifecycleCallbacks: { }

Error 42601 using postgresql and dart

I get the error 42601 when using postgresql
I created the table using pgAdmin. The autogenerated code looks as follows.
-- Table: posts
-- DROP TABLE posts;
CREATE TABLE posts
(
post_id bigserial NOT NULL,
title character varying(150) NOT NULL,
description character varying(500),
posted_at timestamp with time zone,
last_edited timestamp with time zone,
"user" character varying(50) NOT NULL,
editor character varying(50),
up_votes integer NOT NULL,
down_votes integer NOT NULL,
flag character varying(7),
CONSTRAINT "PK_post_id" PRIMARY KEY (post_id),
CONSTRAINT "FK_user" FOREIGN KEY ("user")
REFERENCES users (login) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
OIDS=FALSE
);
ALTER TABLE posts
OWNER TO postgres;
I execute an insert operation with the following helper method.
addPost(Map values){
connect(uri)
.then((conn){
conn.execute('insert into posts values(#title, #description, now(), now(), #user, #editor, #upVotes, #downVotes, #flag', values)
.then((_) => conn.close())
.catchError((err){
print('Execute error in addPost: $err');
})
.whenComplete(() => conn.close());
})
.catchError((err) => print('Error in addPost: $err'));
}
where Map values has the form:
{'title': 'Sample title', 'description': 'This is a description for a sample post', 'user': 'dartUser', 'editor': 'dartUser', 'upVotes': 0, 'downVotes': 0, 'flag': 'healthy'}
I'm not a postgresql expert, so this might be something trivial I just don't see.
You can find the error codes for postgresql here. Error 42601 means a syntax error.
I suspect the cause is that you are missing a closing bracket on the 'values' clause, after #flag.