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?

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

1 Answer 1

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

10
  • 1
    Where? Did you put a space between the dash and the d? -d? Commented Jun 19, 2018 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? Commented Jun 19, 2018 at 6:32
  • 1
    @CodenameK do you have anything in your psqlrc? Commented Jun 19, 2018 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
    – user1822
    Commented Jun 19, 2018 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. Commented Jun 19, 2018 at 19:03

Your Answer

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

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