어떻게 설명할 수 있는 '표' s # 39 의 avamer 실행하십시오 Oracle&, PostgreSQL (파스크라 명령을 사용하여)?
이 시도하시겠습니까 (flash. '파스크라' 명령줄 도구):
\d+ tablename
참조 [직접] [1] 에서 자세한 정보.
[1]: http://www.postgresql.org/docs/current/interactive/app-psql.html # 파스크라 metalun 명령의세 app
Postgresql (# 39, & # 39, something& \d 외에 운행에서어떠한 # 39, & # 39 또는 \dt table&. # 39, & # 39 또는 \ds sequence&. 등)
같이 표준 SQL 운행에서어떠한 [here] [1]:
select column_name, data_type, character_maximum_length
from INFORMATION_SCHEMA.COLUMNS where table_name = '<name of table>';
많은 데이터베이스 (db) 에 의해 지원되는 it& # 39 개의 키.
[1]: https://stackoverflow.com/questions/100504/what-is-the-sql-command-to-return-the-field-names-of-a-table # 100513
파스크라 의 스케쳐내 대신 스키마에는 카탈로그화할 쿼리합니다 쿼리하지 얻어야 합니다 수 있습니다. # 39 의 다음과 같은 복잡한 here& 않는 쿼리하지
<;;;;! - < pre> < code> 언어: sql - > 선택합니다. f.타누마 tpc. 번호, 이름과 f.타나미, f.타누마, f.타노뉴얼 노뉴얼 있다, pg_catalog.format_type (프리아티피드, 프리아티페모드) 등의 유형, 케이스 P.콘티페 p& # 39, & # 39 때, = 그럼 # 39, & # 39 t&.
프리마리키 로 종료, 케이스
우니크키 로 종료, 케이스
포르니키 로 종료, 케이스
Foreignkey_fieldnum 로 종료, 케이스
포르니키 로 종료, 케이스
Foreignkey_connnum 로 종료, 케이스
기본값으로 끝 Pg_attribute 에서 f C 의 프리스트레이트 참가하십시오 pg_class 크리스토퍼로이드 = T 를 프리아티피드 참가하십시오 pg_type t.로이드 = D 의 왼쪽 bigadmin pg_attrdef 크리스토퍼로이드 및 d.드 섬 f.타누마 d.드렐리드 = = N 의 왼쪽 bigadmin pg_namespace 크리스토퍼렐남스파스 니컬러스로이드 = P = (p.콘키) 의 모든 왼쪽 bigadmin pg_constraint p.콘렐리드 크리스토퍼로이드 및 f.타누마 = G 의 왼쪽 bigadmin pg_class p.콘프레이드 = 고드로이드 있다
및 f.타누마 >. order BY 숫자 0 . < /code> < /pre>;;;
It& # 39 의 꽤 복잡한 하지만 않니다 보여줄 수 있는 전력 및 유연성 및 PostgreSQL 시스템 카탈로그를 받아야 하는 너회가 위한 방안 pg_catalog 합격; -). # 39 의 수, %s& 변경하십시오 아웃해야 질의입니다. 첫 번째는 스키마에는, 두 번째는 테이블 이름.
',' You table_name> < \d+ 명령줄이 외에도 이미 찾은 사용할 수도 있습니다. 정보 스키마, info_schema.columns 사용하여 열 데이터 조회
SELECT *
FROM info_schema.columns
WHERE table_schema = 'your_schema'
AND table_name = 'your_table'
다음 SQL 문을 사용하여
SELECT DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'tbl_name'
AND COLUMN_NAME = 'col_name'
이 경우, 특정 데이터 유형 및 col_name 대체하는지 tbl_name 표시합니다. 콜로기나 찾고 있습니다.
이 쿼리하지 (설명에 따라 다른 대답을) 의 변형 협력했습니다 for me.
SELECT
COLUMN_NAME
FROM
information_schema.COLUMNS
WHERE
TABLE_NAME = 'city';
http://www.postgresqltutorial.com/postgresql-describe-table/
, MySQL 에서 table_name 설명합니다.
Postgresql 의 table_name \d ,
또는 이 긴 명령을 사용할 수 있습니다.
SELECT
a.attname AS Field,
t.typname || '(' || a.atttypmod || ')' AS Type,
CASE WHEN a.attnotnull = 't' THEN 'YES' ELSE 'NO' END AS Null,
CASE WHEN r.contype = 'p' THEN 'PRI' ELSE '' END AS Key,
(SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid), '\'(.*)\'')
FROM
pg_catalog.pg_attrdef d
WHERE
d.adrelid = a.attrelid
AND d.adnum = a.attnum
AND a.atthasdef) AS Default,
'' as Extras
FROM
pg_class c
JOIN pg_attribute a ON a.attrelid = c.oid
JOIN pg_type t ON a.atttypid = t.oid
LEFT JOIN pg_catalog.pg_constraint r ON c.oid = r.conrelid
AND r.conname = a.attname
WHERE
c.relname = 'tablename'
AND a.attnum > 0
ORDER BY a.attnum
SELECT
n.nspname as schema,
c.relname as table,
f.attname as column,
f.attnum as column_id,
f.attnotnull as not_null,
f.attislocal not_inherited,
f.attinhcount inheritance_count,
pg_catalog.format_type(f.atttypid,f.atttypmod) AS data_type_full,
t.typname AS data_type_name,
CASE
WHEN f.atttypmod >= 0 AND t.typname <> 'numeric'THEN (f.atttypmod - 4) --first 4 bytes are for storing actual length of data
END AS data_type_length,
CASE
WHEN t.typname = 'numeric' THEN (((f.atttypmod - 4) >> 16) & 65535)
END AS numeric_precision,
CASE
WHEN t.typname = 'numeric' THEN ((f.atttypmod - 4)& 65535 )
END AS numeric_scale,
CASE
WHEN p.contype = 'p' THEN 't'
ELSE 'f'
END AS is_primary_key,
CASE
WHEN p.contype = 'p' THEN p.conname
END AS primary_key_name,
CASE
WHEN p.contype = 'u' THEN 't'
ELSE 'f'
END AS is_unique_key,
CASE
WHEN p.contype = 'u' THEN p.conname
END AS unique_key_name,
CASE
WHEN p.contype = 'f' THEN 't'
ELSE 'f'
END AS is_foreign_key,
CASE
WHEN p.contype = 'f' THEN p.conname
END AS foreignkey_name,
CASE
WHEN p.contype = 'f' THEN p.confkey
END AS foreign_key_columnid,
CASE
WHEN p.contype = 'f' THEN g.relname
END AS foreign_key_table,
CASE
WHEN p.contype = 'f' THEN p.conkey
END AS foreign_key_local_column_id,
CASE
WHEN f.atthasdef = 't' THEN d.adsrc
END AS default_value
FROM pg_attribute f
JOIN pg_class c ON c.oid = f.attrelid
JOIN pg_type t ON t.oid = f.atttypid
LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
LEFT JOIN pg_namespace n ON n.oid = c.relnamespace
LEFT JOIN pg_constraint p ON p.conrelid = c.oid AND f.attnum = ANY (p.conkey)
LEFT JOIN pg_class AS g ON p.confrelid = g.oid
WHERE c.relkind = 'r'::char
AND f.attisdropped = false
AND n.nspname = '%s' -- Replace with Schema name
AND c.relname = '%s' -- Replace with table name
AND f.attnum > 0
ORDER BY f.attnum
;
아래의 쿼리를 사용하여 확인할 수 있습니다
Select * from schema_name.table_name limit 0;
엑스프 플레: 테이블에는 2 단 내 이름과 비밀번호. 확증하노라 스크린샷 같습니다.
In postgres \d is used to describe the table structure.
e.g. \d schema_name.table_name;
this command will provide you the basic info of table such as, columns, type and modifiers.
If you want more info about table use
\d+ schema_name.table_name;
this will give you extra info such as, storage, stats target and description
Use this command
\d table name
like
\d queuerecords
Table "public.queuerecords"
Column | Type | Modifiers
-----------+-----------------------------+-----------
id | uuid | not null
endtime | timestamp without time zone |
payload | text |
queueid | text |
starttime | timestamp without time zone |
status | text |
내가 일했던 아웃해야 정보정의다음 스크립트입니다 다음에서 테이블 스키마.
'CREATE TABLE ' || 'yourschema.yourtable' || E'\n(\n' ||
array_to_string(
array_agg(
' ' || column_expr
)
, E',\n'
) || E'\n);\n'
from
(
SELECT ' ' || column_name || ' ' || data_type ||
coalesce('(' || character_maximum_length || ')', '') ||
case when is_nullable = 'YES' then ' NULL' else ' NOT NULL' end as column_expr
FROM information_schema.columns
WHERE table_schema || '.' || table_name = 'yourschema.yourtable'
ORDER BY ordinal_position
) column_list;