Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Say I need hand write some queries in the console, what's the most efficient way of executing mulitline queries like CREATE TABLE statements? I am used to using Microsoft Management Studio, but I now find myself having to learn about postgres on the fly. Thanks

share|improve this question
    
Type it in? Copy and paste? Redirect from a file? –  Michael Hampton Aug 8 '12 at 1:39
    
Yes I mean type it in with my fingers :P. What I'm getting at is that the postgres # prompt appears only enter one line at a time which is great for things like CREATE DATABASE or ALTER USER. How would I be able to nicely format my text before executing? –  hydroparadise Aug 8 '12 at 1:43

1 Answer 1

up vote 4 down vote accepted

There is really no such thing as a "multi-line query" - As far as Postgres cares all that whitespace and those newlines are meaningless (unless they occur inside a string or we're talking about tabs & such in a COPY statement or a few other special places).

Writing queries "on the console" over SSH is usually done with the psql tool, which is the Postgres interactive terminal (see the docs for more info). This is also what you would pas text files containing queries to.
You can also pass queries to psql on the command line. (quoted as appropriate for your shell) or pipe them in via STDIN (the standard input stream).

share|improve this answer
    
Pipes, should have thought about pipes. I still learn. –  hydroparadise Aug 8 '12 at 1:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.