Join Postgresql Tables with naming convention -


say have many postgresql tables same columns , sort of naming convention.

tablename_descriptor:        tablename_anotherdescriptor:      tablename_descriptor3:   id         value             id           value                id        value 1          val1              1            val4                 1         val7 2          val2              2            val5                 2         val8 3          val3              3            val6                 3         val9 

is there way join tables name begins "tablename"? giving result

tablename: id       value 1        val1 2        val2 3        val3 4        val4 5        val5 6        val6 7        val7 8        val8 9        val9 

here dynamic sql, results of can execute various tables union all'd together.

select string_agg('select row_number() on () rn,value ' || tablename,' union ') pg_catalog.pg_tables schemaname = 'public' , tablename ~* e'tablename\\_descriptor'; 

1). row_number() there give id (or supply sequence etc).

2). if working command line, execute query in 1 psql session , pipe results of generated query.

eg.

psql -u <youruser> -d <yourdb> -qtac "<the query>" | psql -u <youruser> -d <yourdb> 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -