Solved

Issue with MySQL VIEW column size

Posted on 2009-04-13
6
377 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 142

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 142

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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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 142

Expert Comment

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

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

810 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