I want to parse a SQL file and print only the create table statements.
Example SQL file:
--
-- Name: film_actor; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.film_actor (
actor_id smallint NOT NULL,
film_id smallint NOT NULL,
last_update timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE public.film_actor OWNER TO postgres;
--
-- Name: film_category; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.film_category (
film_id smallint NOT NULL,
category_id smallint NOT NULL,
last_update timestamp without time zone DEFAULT now() NOT NULL
);
ALTER TABLE public.film_category OWNER TO postgres;
Here, I just want to get the complete create table statement for the first table and then print, then go for the next table.
I tried to use it with DDLparse and SQLparse tools, but not exactly parse the complete SQL file. So basically once I grep the Create table statement then I can use SQLparse to do other stuff.
Could someone help me with this?