0

Is there a way in which I can get the table definition in a script that I can execute?

i.e.

I have a table "cities":

CREATE TABLE public.cities
(
    name character(80) COLLATE pg_catalog."default" NOT NULL,
    location point,
    CONSTRAINT pk_city_name PRIMARY KEY (name)
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

ALTER TABLE public.cities
    OWNER to postgres;

is there a way I can generate that with a script rather than using the GUI?

2

2 Answers 2

0

If you want to write your commands into a script file, and the run it from command line, you should use psql -f <filename>.

See https://www.postgresql.org/docs/9.2/static/app-psql.html

Sign up to request clarification or add additional context in comments.

1 Comment

I think the OP is asking for the script to be created using the CLI (not just written out to file). For example, output the above script by specifying the table cities, but without using the GUI.
0

Thanks for the links and places to look.

for those reading what I done:

open cmd

navigate to C:\Program Files\PostgreSQL\10\bin> (or create a short cut)

pg_dump -d mydb -t cities -U postgres -h localhost > C:/test/weather.sql

enter password for postgres

file is output to directory.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.