some weird values that i can't insert it into my psql table - mysql

I downloaded a data file crawled from an auto information website.
Basically it looks like this:
after I import it using \i in psql.
i got this error:
Invalid command \',. Try \? for help.
i tried the create table part without insert any rows. it can create a table successfully.
and i manually insert some rows from this file. some of them works, others doesn't.
so i guess there are some weird values in the values that i insert.
some weird values like '前● / 后●' can be insert, but until i found this:
'[u\'#70706E\', u\'#854C38\']'
when i insert this, it gives me the same error message.
Could some one tell me what does this value mean? why it can't be insert and how do they get it when they use crawler to crawl the data from the website?

Related

Remove repeated lines from a text file in order for phpMyAdmin to successfully insert SQL statements into database

I have a large text file full of INSERT SQL statements that I want to insert into a phpMyAdmin database. The problem I am having is that many of these INSERT statements within this file are identical, resulting in “Duplicate Key” error occuring.
Is there a way to make phpMyAdmin ignore the repeated SQL statements? I have tried running the file through a .vbs script that removes duplicate lines but it failed to deliver.
Logic that I am thinking of so far is the following:
Run the file through a script that removes duplicate lines.
Find a solution in which phpMyAdmin ignores repeated lines.
Has anyone got any other ideas or suggestions on how I could solve this problem?
The easy way is by using INSERT IGNORE statement, but you will not know which record is duplicate.
another way, by create new table like 'table2' with no primary key or unique key, insert all the data into it, then INSERT IGNORE to your main table before, and compare which row are duplicate. Or maybe you can use the COUNT() function to get the duplicate row by.

How to insert a row of data in my MySQL table from command line?

I'm using MySQL command line and need to insert data into my table. I'm having a major brain fart and feel really rusty on this and cannot remember on how to do this correctly. Here is how my table looks currently:
I deleted items from my database, and this is all that is left in my books table. I want to add another book that has the title "Faith" and the author "Nelson", so I tried the following command, but get an error as you can see below:
I don't want to enter information for the key, I want it to generate automatically without me having to manually enter it. Can someone please show me how to enter this data correctly? Thanks.
Try this:
INSERT INTO books (`title`, `author`)
VALUES
('faith', 'nelson');

Insert Error on Delete

So I am trying to delete a record from a table and it is getting the strangest error.
The query is
DELETE FROM table where column1='x' and column2='y'
note I entered mock names for the table and columns for security reasons.
Any way I am receiving the error:
Msg 213, Level 16, State 1, Procedure CustomVLANPicsMaintenance, Line 11
Insert Error: Column name or number of supplied values does not match table definition.
Which is strange since this is a delete and not an insert. There are many many stored procedures that are on this server but this specific one "CustomVLANPicsMaintenance" does not exsist anywhere!!!!!! Its not even related to the table I'm trying to delete rows from. Whats even more odd is that until recently, the delete method has been working. I cannot find any links from this table or anything that says it should be running a procedure on delete (although Im not too entirely sure where I would find this).
Has anyone gotten something like this before?
I'd first try checking if there are any DELETE triggers present on the table. In Management Studio trigger list is located under Databases/%DB name%/Tables/dbo.%Table name%/Triggers.

MySQL workbench insert statement not working

So I've been playing around with MySQL lately, and being a long time MSSQL user I'm a little new to it.
I've been using the workbench to generate some insert statements, and while I'm sure it was working before it seems to be having trouble now.
When I right click on a table and select "Send to SQL editor" and then select "Insert statement", it gives me some SQL that looks like:
INSERT INTO `mybigtable`.`itemcollection`
(`ID`,
`Type`,
`Name`,
`Description`,
`SomeID`)
VALUES
(
{ID: 123},
{Type: 1},
{Name: '123'},
{Description: '1234'},
{SomeID: 1}
);
This always throws an error at the ID value point, saying it doesnt understand the : symbol (keeping in mind I made no modifications to the code it generated). Now every insert statement I've seen online for MySQL (and insert statements I'm used to in general) dont have the names before the values, the values contain JUST the values. If I remove all the names from before the values, the insert statement works fine.
So while it's ok if I build the insert statements on my own, it seems odd that the "Send to SQL editor" just doesnt work. Am I missing a step here? Is there something in my settings that might be wrong? Why would it generate SQL with the field names before the values if it cant actually use them?
Bah, frustrating.
Those are most likely placeholders for where you are to enter your own values manually. It doesn't know automatically what values you wanted to insert, so it can't populate the whole query for you. Instead, it gives you example values so you know what type of data needs to be inputted, then you need to specify the data yourself. SQL Server does the same thing (right-click table, script table as, insert):
INSERT INTO [5819338].[dbo].[Customer]
([ID]
,[Name])
VALUES
(<ID, int,>
,<Name, varchar(50),>)
And I believe there is a shortcut key to display a popup window where you can enter the template values. Perhaps there is a similar thing in the MySQL editor? I don't know.

mysql strange "duplicate entry" error

I have a problem I don't quite understand. I parse some feeds with Ruby and save their contents in a database. I created a "hash"-column which is the md5-hash of every post url. That column is UNIQUE because I don't want to post anything twice.
It works fine actually:
Mysql::Error: Duplicate entry '28edb7c2b3cd074d226fc4ae37baedd7' for key 'hash'
But the script stops at this point. I don't get that, I know for a fact that using INSERT with PHP always worked like a charm, so if there was duplicate entry it ignored it and went on.
Can anybody help me? Would "INSERT IGNORE" create a double entry or would it just ignore the error message and go on?
Sounds like your Ruby script needs some exception handling.
You can rewrite your query so that instead of INSERT INTO it uses
REPLACE INTO ...
or
INSERT INTO ... ON DUPLICATE KEY UPDATE
This way attempting to insert a duplicate key will update the existing record instead of erroring out.
See here and here for more information.
Update:
INSERT IGNORE not touch your existing data if it encounters a duplicate key. The documentation says:
You can use REPLACE instead of INSERT
to overwrite old rows. REPLACE is the
counterpart to INSERT IGNORE in the
treatment of new rows that contain
unique key values that duplicate old
rows: The new rows are used to replace
the old rows rather than being
discarded.
If you use the IGNORE keyword, errors
that occur while executing the INSERT
statement are treated as warnings
instead. For example, without IGNORE,
a row that duplicates an existing
UNIQUE index or PRIMARY KEY value in
the table causes a duplicate-key error
and the statement is aborted. With
IGNORE, the row still is not inserted,
but no error is issued.
In PHP, if MySQL returns an error, it doesn't normally kill the PHP script. It sounds to me as though that's not the case in Ruby. Either catch the exception and process it or use INSERT IGNORE, in which case MySQL returns a warning instead of an error (unless it was told not to).
"INSERT IGNORE" Should Prevent Ruby from exiting and shouldn't effect your data. However if you want to know when this is happening you have to put in some error handling.
begin
DATABASE.query(insertHash)
rescue
puts "Error: " + $!.to_s + "Backtrace >>: " + $#.to_s
end
Should show the error with out exiting the ruby script.
Or you could use this to indicate to the user that there is already an entry
Hope this helps