教程 > postgresql 教程 > 阅读:63

postgresql select语句——迹忆客-ag捕鱼王app官网

postgresql select语句用于从数据库表中取数据,以结果表的形式返回数据。这些结果表称为结果集。

语法

select 语句语法格式如下:

select column1, column2,...columnn from table_name;

column1、column2...是表的字段;table_name 为表名。如果要获取该表中可用的所有字段,则可以使用以下语法

select * from table_name;

在上一章节 insert into 语句 中,我们已经向表 company 插入了一些数据,使用 * 号可以读取该表的所有数据:

jiyik_db=# select * from company;

结果如下:

id        name        age        address     salary   join_date
----      ----------  -----      ----------  -------      --------
1         paul        32         california  20000.0      2001-07-13
2         allen       25         texas                    2007-12-13
3         teddy       23         norway      20000.0
4         mark        25         rich-mond   65000.0      2007-12-13
5         david       27         texas       85000.0      2007-12-13

我们也可以读取指定字段 id 和 name:

jiyik_db=# select id,name from company;

结果如下:

 id | name  
---- -------
  1 | paul
  2 | allen
  3 | teddy
  4 | mark
  5 | david
(5 rows)

查看笔记

扫码一下
查看教程更方便
网站地图