1

This is the command to create a new database,

CREATE DATABASE mydb;

This is the command to create a new table,

CREATE TABLE IF NOT EXISTS mytable ( int a PRIMARY KEY );

But this does not add the mytable inside the mydb. How to add the table inside the database mydb?

  • 1
    what operating system are you using? – Evan Carroll Jun 19 '18 at 6:10
  • Windows 10 (64bit) – Codename K Jun 19 '18 at 6:18
2

But this does not add the mytable inside the mydb. How to add the table inside the database mydb?

You have to connect to the database mydb,

psql -d mydb

Then run the command

  • 1
    Where? Did you put a space between the dash and the d? -d? – Evan Carroll Jun 19 '18 at 6:30
  • 1
    so where is that error coming from, I have no idea. Does your table name or column name have a - in it? – Evan Carroll Jun 19 '18 at 6:32
  • 1
    @CodenameK do you have anything in your psqlrc? – Evan Carroll Jun 19 '18 at 6:38
  • 2
    @CodenameK: you need to run that on the windows command line. That is not a SQL statement. You simply start psql and connect to the new database. If you already started psql you need to use \connect to switch to a different database – a_horse_with_no_name Jun 19 '18 at 7:12
  • 1
    If the database is dropped, you can't connect to it to see if the table exists. And no one can be connected to the database that you're dropping. You have to drop it while connecting to a different database. – Evan Carroll Jun 19 '18 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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