pdna
pdna

Reputation: 602

Postgres insert into a table

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.

Upvotes: 0

Views: 1525

Answers (2)

Anand Singh
Anand Singh

Reputation: 210

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');

Upvotes: 1

Racil Hilan
Racil Hilan

Reputation: 25351

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.

Upvotes: 1

Related Questions