简体   繁体   English

Postgres插入表格

[英]Postgres insert into a table

I have a SQL script like this which I run from the command line using psql : 我有一个这样的SQL脚本,可以使用psql从命令行运行:

insert into "A"."B" values
(1, 'name=a', 'a@example.com', 'K')

How do I convert it into INSERT command inside a database? 如何在数据库内部将其转换为INSERT命令?

INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1) 
VALUES ('2', 'name=a', 'a@example.com.com', 'K');

Also what does "A"."B" do? 还有"A"."B"做什么? 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. 当我在数据库中运行命令时,似乎出现了一个错误。

You can use this query where A is schema and B is table name. 您可以使用此查询,其中A是架构,B是表名。

INSERT INTO "A"."B" (first_column, second_c, third_c, fourth_1) 
VALUES ('2', 'name=a', 'a@example.com.com', 'K');

You said that your database name was DB and your table name was B . 您说数据库名称为DB ,表名称为B

You can simply use the table name alone: 您可以只使用表名:

INSERT INTO "B" (first_column, second_c, third_c, fourth_1) 
VALUES ('2', 'name=a', 'a@example.com.com', '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', 'a@example.com.com', 'K');

The double quotes are only required when the name of any entity (eg table, column, etc...) is a reserved word. 仅当任何实体的名称(例如表,列等)为保留字时,才需要双引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM