2

I'm trying to get the postgresql table column name. I've tried using information_schema but it doesn't work on my java mvc project. What should I do ?

This is actually my first question on StackOverflow, so I'm sorry if my question is difficult to understand. Thank you!

public interface MyFileRepository extends JpaRepository<MyEntityModel, Long> {
    @Query("select column_name,data_type from information_schema.columns where table_name = 'MyEntityModel';")
    List<MyEntityModel> myList();
}
S.Daineko
  • 1,790
  • 1
  • 20
  • 29

1 Answers1

0

About schema. You can set default schema by two ways:

  1. Put it to the properties(or .yml file) spring.datasource.schema = #your schema name

  2. Put it in your entity model @Table(schema = "SCHEMA_NAME")

About getting information about table you can look this one open question:

Is there any Simplest way to get Table metadata (column name list) information, in Spring Data JPA ? which could I use on universal database

S.Daineko
  • 1,790
  • 1
  • 20
  • 29