Skip to main content
Question

Keep only columns in a PostGis data if they are not listed in the text file

  • November 15, 2019
  • 4 replies
  • 19 views

Forum|alt.badge.img

Hello

I want to export a table from PostGis databse by keeping only the columns that don't appear in a text file.

This is an example to be more clear :

 

Text_file : A B C Z

Table columns :

ID

 

7

 

T

 

Z

 

F

 

K

 

B

 

 

 

 

 

 

 

 

 

Export result:

ID

 

7

 

T

 

F

 

K

 

 

 

 

 

 

 

Thank you in advance for your answers.

Best Regards

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

4 replies

redgeographics
Celebrity
Forum|alt.badge.img+62

You could read the text file and per feature in there have an SQLExecutor perform an ALTER table DROP column query.

However... this screams "massive SQL injection vulnerability" so I would recommend that you make really really sure the input text file is correct.


Forum|alt.badge.img
  • Author
  • December 10, 2019

You could read the text file and per feature in there have an SQLExecutor perform an ALTER table DROP column query.

However... this screams "massive SQL injection vulnerability" so I would recommend that you make really really sure the input text file is correct.

Hello and thank you very much for your answer. Sorry for my late answer.

Do you think there's any other way then this sql query ?

Thank you very much in advance for your answer.


redgeographics
Celebrity
Forum|alt.badge.img+62

Hello and thank you very much for your answer. Sorry for my late answer.

Do you think there's any other way then this sql query ?

Thank you very much in advance for your answer.

Well... I'm no SQL wizard, but one thing you can try is

  1. Create a view (as SELECT * FROM table)
  2. Drop the columns you don't want from that view (with the ALTER view DROP column)
  3. SELECT * FROM view, run the data through your process
  4. Drop the entire view

Each step is a separate SQLExecutor. It'll leave the original table untouched.


nielsgerrits
VIP
Forum|alt.badge.img+64

Well... I'm no SQL wizard, but one thing you can try is

  1. Create a view (as SELECT * FROM table)
  2. Drop the columns you don't want from that view (with the ALTER view DROP column)
  3. SELECT * FROM view, run the data through your process
  4. Drop the entire view

Each step is a separate SQLExecutor. It'll leave the original table untouched.

This. But if you are not allowed to create a view (which is often the case in my experience) you also could generate the select query. I can think of two ways:

  1. Use a SQLExecutor to Retrieve all colunms from the table from information_schema.columns. (select * from information_schema.columns where table_schema = 'public' and table_name = 'spatial_ref_sys';)
  2. Get one row (select * from public.spatial_ref_sys limit 1;) and use an AttributeExploder to extract the columns. Remove all columns starting with fme_ using a Tester.

Then use a FeatureMerger to merge with the checklist (Supplier). Unmerged Requestors are the columns not in the checklist. Aggregator to concat all remaining columns, AttributeCreator to create select statement. (select srid,auth_name,auth_srid,srtext,proj4text from public.spatial_ref_sys;) Use a SQLExecutor to run the concatted selectstatement.