将多个CSV文件保存到多个表格中的表格输出。

huangapple go评论42阅读模式
英文:

save multiple csv to multiple table in table output

问题

我有多个CSV文件,例如1.csv、2.csv、3.csv,然后我想在我的Postgres数据库中为每个CSV文件创建新表格。

目前我正在使用"获取文件名"来读取包含多个CSV文件的文件夹,然后我使用"CSV文件输入"来读取这些CSV文件。之后我不确定应该使用什么函数来保存/创建新表格在我的Postgres数据库中。

我应该采取哪些步骤?

我已经尝试使用"表格输出"但对我来说没有起作用。我不确定可能是我配置了一些错误的设置。

我期望根据我的CSV文件名在我的Postgres中有多个表格。

英文:

I have multiple csv file for example 1.csv,2.csv,3.csv then I want to create each csv file new tables in my postgres database.

currently im using "get file names" to read my folder that contains multiple csv files, then im using "CSV file input" to read the multiple csv files. After that I not sure what function should I use to save/create new tables in my postgres database.

What step I should use ?

I already try to use table output but doesnt work for me. Im not sure maybe there some wrong setting I configure.

I expect that I will have multiple tables in my postgres base on my csv file name.

答案1

得分: 1

你可能不确定想要实现什么,但有不同的方法可以做到。

你可以通过为每个csv设置一个“csv文件输入”步骤,然后将结果发送到一个“表格输出”步骤来解决这个问题。

一个更复杂但更好的解决方案是首先读取csv的标题,然后根据文件名和标题列表进行元数据注入处理,在此过程中创建一个表格(以文件命名),其列基于标题名称(全部为文本,因为你不知道类型),然后加载csv(列以标题命名),之后将结果(标题名称)中的字段插入到表格(以文件命名)中的字段中(也是标题名称)。然后你可以将任意数量的csv插入其中,它们都将最终出现在你的数据库中。

英文:

Not exactly sure what you want to accomplish, but there are diffrent ways to do this.

You can approach this by setting up a "csv file input" step for each csv, and by sending the result to a "table output" step.

A more complex but nicer sollution would be to read out the header of the csv first, and then based on the filename and the header list have a metadata-injected proces where you create a table (named after file) with columns based on the headernames (all text, since you don't know the type) and then load the csv (columns named after headers), after which you insert the fields from the result (headernames) into the fields in the table (named after file) with it's columns (also headernames). Then you can just insert any number of csvs into this and they will all just end up in your database.

答案2

得分: 0

我通常在PostgreSQL中创建表格(不包含列),一旦表格创建完成,表格输出将会添加列并插入数值,没有问题。

也许这不是最高效的方法,但创建少量表格在时间和复杂性方面不应该是一个大问题...在某些Pentaho版本中,创建表格可能会有困难。

英文:

I usually create the table in postgres (with no columns), with the table created, the table output will add the columns and insert the values with no issues.

maybe it's not the most eficient method, but creating few tables should not be a big problem in terms of time and complexity...postgres in some pentaho versions do have a difficult to create tables.

huangapple
  • 本文由 发表于 2023年7月18日 10:02:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709104.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定