简体   繁体   English

SELECT语句以显示额外的列

[英]SELECT statement to show extra columns

Table1 表格1

Code | 代码 Type | 类型 Color | 颜色| Description | 描述

1 | 1 | Fruit | 水果 Red | 红色| apple 苹果

1 | 1 | Fruit | 水果 Orange | 橙色| peach 桃子

1 | 1 | Fruit | 水果 Blue | 蓝色| blueberry 蓝莓

1 | 1 | Fruit | 水果 Green | 绿色| sour apple 酸苹果

1 | 1 | Fruit | 水果 Yellow | 黄色| lemon 柠檬

I'm running the code below: 我正在运行以下代码:

SELECT
code,
type,
color,
description
FROM table

If someone sends me a CSV with additional columns is there a code that I can add that produces the string Error in the additional columns fields? 如果有人向我发送包含其他列的CSV,是否有我可以添加的代码在其他列字段中产生字符串Error

I won't know the additional columns name since it's up to the user to designate it--All I want to produce is the effect that if they did I'll know if there was an additional field added. 我不知道其他列的名称,因为要由用户指定它-我要产生的效果是,如果不指定,我将知道是否添加了其他字段。

The MySQL LOAD DATA command MySQL LOAD DATA命令

  • Ignores extra columns in the input file and possibly produces a warning if they are found 忽略输入文件中的多余列,如果发现多余列,可能会产生警告
  • Doesn't give names to input file columns; 不给输入文件列指定名称; it assigns their values to table columns and variables, which are fixed (either implicit in the tble definition or explicit in the LOAD DATA command) 它将它们的值分配给固定的表列和变量(在tble定义中隐式或在LOAD DATA命令中显式)

In other words, you'll always load Code , Type , Color and Description into your table, regardless of input malformations. 换句话说,无论输入格式如何,都将始终将CodeTypeColorDescription加载到表中。

There is a possible workaround to find lines with one or more extra columns: load the file into an empty auxiliary table with 5 columns with a NULL default. 有一种可能的解决方法来查找具有一或多个额外列的行:将文件加载到具有5列且默认值为NULL的空辅助表中。 If any line in the CSV file has 5 or more columns, the test table will contain records in which the fifth column IS NOT NULL ; 如果CSV文件中的任何一行有5列或更多列,则测试表将包含第五IS NOT NULL you can count them. 你可以数一下

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM