Note that there are some explanatory texts on larger screens.

plurals
  1. POSELECT * INTO OUTFILE from a view doesn't work, but the underlying query works fine INTO OUTFILE
    primarykey
    data
    text
    <p>I'm running a query that does a calculation based on some views, and writes the results to a file. It looks like this:</p> <pre><code>select `v1`.`id` AS `id`,`v2`.`name` AS `name`, `v2`.`nbr` AS `nbr`, `v1`.`nbr` AS `total`, (`v2`.`nbr` / `v1`.`nbr`) AS `percent` INTO OUTFILE '/home/username/mysqldump/filename.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' from `v2` join `v1` where `v2`.`id` = `v1`.`id` </code></pre> <p>That works great. I created a view based on this query, but it doesn't work as a drop-in replacement, as I expected. Here's the "Create View" portion of SHOW CREATE VIEW: </p> <pre><code> CREATE ALGORITHM=UNDEFINED DEFINER=`user`@`localhost` SQL SECURITY DEFINER VIEW `view_name` AS select `v1`.`id` AS `id`, `v2`.`name` AS `name`, `v2`.`nbr` AS `nbr`, `v1`.`nbr` AS `total_pvs`, (`v2`.`nbr` / `v1`.`nbr`) AS `percent` from (`v2` join `v1`) where (`v2`.`id` = `v1`.`id`) </code></pre> <p>Here's the query that doesn't work:</p> <pre><code> SELECT * INTO OUTFILE '/home/username/mysqldump/filename.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM view_name; </code></pre> <p>I got this error:</p> <p><code>ERROR 1356 (HY000): View 'database_name.view_name' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them</code></p> <p>I'm running as root, so I don't think there are any rights issues. What might be making this query invalid in the eyes of MySQL? I'm running version 5.5.32-0ubuntu0.12.04.1 (Ubuntu)</p> <p><strong>EDIT</strong>: Running <code>SELECT * FROM view_name</code> returns the records as expected. However, with thousands of lines, and the need for solid formatting, I would rather use <code>INTO OUTFILE</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload