Solved

Issue with MySQL VIEW column size

Posted on 2009-04-13
6
389 Views
Last Modified: 2013-12-12
Hi,

I have Product table with columns prod_id int(11),category_id int(11),prod_name varchar(255) and prod_quantity varchar(255).
I am creating VIEW in MySQL using above table  and following syntax:

CREATE OR REPLACE VIEW product_view AS
SELECT
 category_id,
 CONCAT("#",GROUP_CONCAT(CONCAT_WS('=',prod_name,prod_quantity) SEPARATOR '#'),"#") AS product_quantity_values

FROM
 product
GROUP BY category_id

Now when i describe VIEW then the column size of VIEW COLUMN "product_quantity_values" shows varchar(343). So this view only allow me to store 343 characters in COLUMN "product_quantity_values" . More than that are truncated.

Is there any way to avoid such behavior? I want the VIEW COLUMN "product_quantity_values" should store more characters.

0
Comment
Question by:teenashah
  • 3
  • 3
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24128586
please try this:
CREATE OR REPLACE VIEW product_view AS
SELECT
 category_id,
 cast(CONCAT("#",GROUP_CONCAT(CONCAT_WS('=',prod_name,prod_quantity) SEPARATOR '#'),"#") AS product_quantity_values as VARCHAR(65000)) 
FROM 
 product 
GROUP BY category_id

Open in new window

0
 

Author Comment

by:teenashah
ID: 24128719
Hi angelIII,

Its giving a error:

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS fproduct_quantity_values as VARCHAR(65000))

BTW: I am using MySQL 5
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24128828
sorry,...
CREATE OR REPLACE VIEW product_view AS
SELECT
 category_id,
 cast(CONCAT("#",GROUP_CONCAT(CONCAT_WS('=',prod_name,prod_quantity) SEPARATOR '#'),"#") as VARCHAR(65000))  AS product_quantity_values 
FROM  product 
GROUP BY category_id

Open in new window

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:teenashah
ID: 24129011
Sorry angelIII,

Same error again.

Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(65000)) AS
0
 

Author Comment

by:teenashah
ID: 24135661
Hi,

Above issue has been resolved.

MySQL 5 CAST function allows type as CHAR Not VARCHAR.

But thanks for giving way to tackle situation.
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24136813
I see, glad I could help.
so, please, close the question.
a3
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Formating field inside mysql query 2 29
PHP: Filling Out/Creating a PDF 29 94
php subtract from date 2 26
Select the 2 most recent visit dates 5 9
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question