LoginSignup
0
0

More than 3 years have passed since last update.

TDにアップロードしたいが、Embulkのymlファイルがないので作るとき

Last updated at Posted at 2020-12-22

information_schemaからこうやってやるメモっす

既にTDのTableに入ってるんだけど、embulkのファイルがないーこれをコネクターで取りたい―とかWFで取りたい―とかの場合
(今回は同一ファイルのIF元が変わるーんだけどembulkのymlが手元にない。先方は現行保障してs3にputするのでwfで取得してね。って言われたパターン)

information_schemaからordinal_position順に書き出せば、すぐにembulkのymlにできそう。(guessできないときの話)

SELECT
    ordinal_position,
    column_name,
    data_type,
    '  - {name: '||column_name||', type: '||case data_type
      when 'varchar' then 'string'
      when 'bigint' then 'long'
      else data_type
    end||'}' as col
FROM
    information_schema.columns
WHERE
    table_schema = '(DB_NAME)'  -- DB名
AND
    table_name = '(Table_NAME)'  -- テーブル名
AND
    column_name != 'time'  -- timeカラムは除外
order by ordinal_position -- 入ってる順番にソート

参考

information schemaから引ける項目
https://dev.mysql.com/doc/refman/5.6/ja/information-schema-columns-table.html

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0