I have a CSV file containing info to be inserted in a database with SQL using insert similar to the below example:
INSERT INTO `Person`(`name`, `occupation`, `residence`, `comments`) VALUES
(GIBEL ΕΛΛΗ,NULL,NULL,NULL)
I want to separate the text values from the null values. Specifically, I want to enquote text values and leave null as it is. Is there a way to do this using Sublime Text 3? Please bear in mind that I am not familiar with regexp. Each field in my DB is either VARCHAR or TEXT.
Example you supplied
INSERT INTO `Person`(`name`, `occupation`, `residence`, `comments`) VALUES (GIBEL ΕΛΛΗ,NULL,NULL,NULL)
Activate RegEx in ST3 Find and Replace.
Find Value
(.*VALUES \()(.*)(,NULL,NULL,NULL\))
Replace Value
$1"$2"$3
Apply Replace All
Result
INSERT INTO `Person`(`name`, `occupation`, `residence`, `comments`) VALUES ("GIBEL ΕΛΛΗ",NULL,NULL,NULL)
Related
How can I insert a value into a column with power? Please see the below example:
Can it be done via the UNISTR function?
insert into table values ('2332239 12'); -- I intentionally want to insert the number into a varchar field.
If you mean you want to insert a string that ends with Unicode superscript 12 you can just put Unicode characters in a Unicode string and insert them into a Unicode column:
INSERT INTO table VALUES(N'123¹²')
(Your column will have to be an NVARCHAR)
If your column is a varchar and you can't change it you'll have to encode the data somehow, and decode it very time you want to use it (not ideal)
I tried to add a row to my table named Clienti, I opened query tool and wrote this query, anyway it isn't working, can you tell me the reason? It says the array isn't correctly defined.
INSERT INTO "Clienti"(
"Nome", "Cognome")
VALUES ('example', 'example2');
The problem is that your fields are defined as arrays of strings, not strings. That's why PostgreSQL is complaining about your INSERT statement: You're trying to put a single string into a field that's defined as an array of strings.
"Nome" character(20)[]
means Nome is an array of strings of 20 characters.
You probably want
"Nome" varchar(20)
(for a string of up to 20 characters)
or
"Nome" text
(for no length limit).
See the PostgreSQL documentation for more information about character types.
Try this insert query it will work.
INSERT INTO Clienti(Nome, Cognome)
VALUES ('example', 'example2');
Trying to BULK INSERT a tab delimited .txt file with a number of columns.
The one giving me issues is just a text string. It sometimes contains quotation marks within the string. Like:
Joseph "Joe" Smith
when I bulk insert, that field ( as varchar(100)) will get inserted like
"Joseph ""Joe"" Smith"
I'm sure the answer is fairly simple, but all my searches turn up issues with quotation-delimited fields, and that's not my issue.
The answer to this depends on what your expected results are.
If you want to remove the quotes completely (i.e. it gets inserted as 'Joseph Joe Smith') then you will need to create a format file and specify it in your bulk insert statement.
The following link will have some more information on what a format file is and how to create/use one: http://blogs.msdn.com/b/sqlserverfaq/archive/2010/02/04/how-to-remove-unwanted-quotation-marks-while-importing-a-data-file.aspx
If you want the value to be true to what the input value is (i.e. 'Joseph "Joe" Smith'), then your best bet is to keep what you have an follow it up with an update statement and use the REPLACE function. Since you have double quotes, it should be relatively simple update statement.
Update YourTable
Set Name = REPLACE(Name, '""', '"')
for example if i had a text file in the following format
A
B
C
D
E
.
.
.
and an sql table calld table with column called letters
i want to insert each value in the text file to the column letters, is it possible to do this directly from SQL Server without using any other programming language?
also is it possible to specify a seperator for the values like "/" or "#"? in case the the text format was A/B/C/D or A#B#C#D?
Yes, exactly. Use BULK INSERT can resolve your issue.
I would like to take a list that I have in a text file, of values which are separated by commas:
Example - 1,2,3,4,5,6,7,8,9,0
then put the values in a database table(I'm going to use this table for auto-complete with jQuery).
I would have done an array for the auto-complete but I have something like 1000 values so I think its better to pull from SQL(am i right?)
Try to explain it to me slowly cause I'm a novice and this is so confusing :)
If those are 1000 constant values (like countries), put them in array.
If they are fairly dynamic, put them in a table
Assuming the table is called T1 and has one field F1, you need to transform the string
1,2,3,4,5,6,7,8....N
to
INSERT INTO T1
VALUES (1),(2),(3),(4),(5),(6),(7),(8)......(N);