import groovy.sql.Sql
sql = Sql.newInstance(
"jdbc:postgresql://localhost:5432/jtrac",
"postgres",
"postgres",
"org.postgresql.Driver")
table = "users"
query = """select
pc.relname,
pa.attname,
format_type(pty.oid, pa.atttypmod) as ft,
pa.attnotnull
from pg_class pc
join pg_attribute pa
on (pa.attrelid = pc.oid)
join pg_type pty
on (pa.atttypid = pty.oid)
where
pc.relname = ${table}
and pa.attnum >= 1
order by pa.attnum"""
sql.eachRow(query){
// 列名
println "attname:${it.attname}"
// 型
println "ft:${it.ft}"
// NOT NULL
println "attnotnull:${it.attnotnull}"
println "----"
}
動作環境
Groovy 1.6.3, JDK6 Update16, Postgres 8.4.0,
8.4-701JDBC4
関連情報
pg_attribute
http://www.postgresql.org/docs/8.4/interactive/catalog-pg-attribute.html
format_type function
http://www.postgresql.org/docs/8.4/interactive/functions-info.html#FUNCTIONS-INFO-CATALOG-TABLE
0 件のコメント:
コメントを投稿