0

I have a SQL script like this which I run from the command line using psql:

insert into "A"."B" values
(1, 'name=a', '[email protected]', 'K')

How do I convert it into INSERT command inside a database?

INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1) 
VALUES ('2', 'name=a', '[email protected]', 'K');

Also what does "A"."B" do? I read somewhere that double quotes are needed when table name has Capitals. I seem to get an error with that when I run commands inside the database.

4
  • 1
    The names are missleading "A"."first_column" means: a table named first_column in a schema named "A" Commented Apr 4, 2018 at 6:06
  • What do you mean with "convert inside a database"? Commented Apr 4, 2018 at 6:08
  • I am not exactly sure of the terminology, but when you connect to a particular DB using psql command and run commands there Commented Apr 4, 2018 at 6:11
  • 1
    You already have an insert statement, so what exactly are you trying to "convert"? Commented Apr 4, 2018 at 6:11

2 Answers 2

1

You said that your database name was DB and your table name was B.

You can simply use the table name alone:

INSERT INTO "B" (first_column, second_c, third_c, fourth_1) 
VALUES ('2', 'name=a', '[email protected]', 'K');

If you want to include the database name, then use:

INSERT INTO "DB"."B" (first_column, second_c, third_c, fourth_1) 
VALUES ('2', 'name=a', '[email protected]', 'K');

The double quotes are only required when the name of any entity (e.g. table, column, etc...) is a reserved word.

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

5 Comments

DB=> select * from "A" DB-> I don't see anything
Database name is DB. How can I know the table name? His command did not throw any error, i made a mistake. But I don't see entries in the table like I do when I run the .sql scripts
Sorry I was confused. I am rolling back a change in my question. B is my table name. I made a dumb mistake
Both the answers are correct, its just that I made a couple of typos in my commands.
1

You can use this query where A is schema and B is table name.

INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1) 
VALUES ('2', 'name=a', '[email protected]', 'K');

2 Comments

After running this, when i run select * from "A"."first_column"; i don't see the entry in the table.
This is identical to the query in the question. So how is this an answer?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.