MySQLでテーブルだとshow create table でCREATE文を確認できたと思うんです
postgresql で show create table をするには
pg_dump -U postgres --schema-only my_db
- --schema-only
- テーブル定義: をつける
- --table=テーブル名
- テーブルを制限する
コマンドからテーブル定義を確認する方法
psql# \d TABLE_NAME
とあるが、これではSELECT文を発行しているだけなので,Create Tableが欲しいの回答にはならない.質問サイトで平然と答える人を見てどうだかなぁとおもう
サンプル
テーブル定義をpsql で \d で確認した場合
takuya@rena:~/Desktop/$ psql my_test my_test=# \d users Table "public.users" Column | Type | Modifiers ------------+--------------------------+---------------------------------------------------- id | integer | not null default nextval('users_id_seq'::regclass) name | character varying(256) | pass | character varying(256) | created_at | timestamp with time zone | Indexes: "users_pkey" PRIMARY KEY, btree (id)
takuya@rena:~/Desktop/$ pg_dump my_test --schema-only --table users ; -- -- PostgreSQL database dump -- SET statement_timeout = 0; SET lock_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SET check_function_bodies = false; SET client_min_messages = warning; SET search_path = public, pg_catalog; SET default_tablespace = ''; SET default_with_oids = true; -- -- Name: users; Type: TABLE; Schema: public; Owner: takuya; Tablespace: -- CREATE TABLE users ( id integer NOT NULL, name character varying(256), pass character varying(256), created_at timestamp with time zone ); ALTER TABLE public.users OWNER TO takuya; -- -- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: takuya -- CREATE SEQUENCE users_id_seq START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; ALTER TABLE public.users_id_seq OWNER TO takuya; -- -- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: takuya -- ALTER SEQUENCE users_id_seq OWNED BY users.id; -- -- Name: id; Type: DEFAULT; Schema: public; Owner: takuya -- ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass); -- -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: takuya; Tablespace: -- ALTER TABLE ONLY users ADD CONSTRAINT users_pkey PRIMARY KEY (id); -- -- PostgreSQL database dump complete --