473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to save query results to blob field

xxoulmate
saving query results to a file
select * from table into outfile savepath

is it possible to save the query result directly to blob field in a table
e.g. something like below
insert into desitination_table_name (blobfield) select * from table
Apr 14 '10 #1
3 3349
Atli
5,058 Expert 4TB
Hey.

You can simply CONCAT all the fields together, which would make them one long string that could be put into a BLOB.

I would question the wisdom of this, though. You would essentially be duplicating data, which is never good.

What exactly are you trying to achieve? Maybe we can offer an alternative.
Apr 17 '10 #2
Current procedure
step 1: (put the query results in a file)
- select * from table into outfile 'c:\test.csv'
step 2: (upload the file in a blob)
- insert into tablename (blob) select load_file('c:\test.csv')

the main goal is to shorten the process.,
instead of doing two steps do it in just one procedure.
Apr 19 '10 #3
Atli
5,058 Expert 4TB
Ok, how about this.

You can create a comma-separated list of all the values in a row by doing something like this.
Expand|Select|Wrap|Line Numbers
  1. SELECT CONCAT_WS(',', field1, field2, fieldN) FROM tbl
This will give you each row, represented as a comma-separated string.

By combining the GROUP_CONCAT function with a GROUP BY NULL clause, the function will give you a single string, created from the value of the selected fields from all rows.
Expand|Select|Wrap|Line Numbers
  1. SELECT GROUP_CONCAT(field1 SEPARATOR '\n')
  2. FROM tbl
  3. GROUP BY NULL
Combine the two, using the result of the CONCAT_WS as the input field for the GROUP_CONCAT function, and you can create a CSV-like string made out of all rows in the table. Use that as the data source for your INSERT query and you should get what you need.

Note that the CSV-like string this generates is not perfect. It will not take into account things like special characters in the values for the fields; both the new-line and double-quote characters will mess up the format of the string.

Also note that duplicating the data like this is usually not a good idea. Can you explain why you need to do this? We may be able to offer a better alternative.
Apr 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: raglin | last post by:
I have a dynamic database that will be periodically queried to select the data from a blob field. This blob data field is text of a variable length. The data will be selected using an id field...
4
by: Luis | last post by:
Hi, I can a big problem... because I have a byte data = new byte, and I need to save this to a field on my MySQL database (here I have a BLOB field) but ¿can I save it? because if I put: Insert...
4
by: dale zhang | last post by:
Hi, I have a C# web application in ASP.Net, which has a user contact info DB in MS Access. Can I add a column to each user to save pdf attachments for each user if needed? If so, how do we do...
5
by: natzol | last post by:
Is there a way to run query, make file out of query (txt,csv or xls - for example) and save it as a blob into the table column type Image/Text? Any thoughts would be greatly appreciated. ...
0
by: Big George | last post by:
Hello, I'm trying to save a jpg file of 300KB as a BLOB field in an Oracle 10g Database. If I try to call a Stored Procedure, it fails. If I use CommandText with SQL sentence, it success. I...
2
by: Vinciz | last post by:
hi guys... im new in java and i would love to learn some of these... basically i got a sample code to retrieve the blob from the mysql. however, i dont really know what to do with these...
4
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing....
10
by: ESIS | last post by:
Hi, I am trying to create a "simple" application, of which, one of the functionalities is to be able to view a PDF Image (Invoice) held in a BLOB field on an SQL Database in the web browser. As...
0
by: hnpatel | last post by:
hello friends, i m making application in vb.NET. i m using MY SQL 5.0 and vs 2005 for this application. Now I want to save image file in sql database. i m using blob datatype of image field. i...
3
by: anandmms | last post by:
Hello friends, I am having a table Personal_Detail, and in that table i am having some fields like name, id, phone_number etc... and also with two blob fields photo1, photo2(allow null). my...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.