获取每个表的前n行

时间:2018-08-31 21:28:49

标签: sql postgresql

我有一个包含约180个表的数据库,我想从所有表中获取前10条记录。有没有一种方法可以在一个查询中执行此操作,或者我需要将它们全部单独编写?

我从AWS迁移了该数据库,需要对每个表中的值类型有一些了解。

理想情况下,这将最终以.csv或某种类型的报告结尾。

1 个答案:

答案 0 :(得分:1)

使用<Field/>

private void loadFromAttributes(AttributeSet attrs, @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
    TypedArray a = ThemeEnforcement.obtainStyledAttributes(this.context, attrs, styleable.ChipDrawable, defStyleAttr, defStyleRes);
    this.setChipBackgroundColor(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_chipBackgroundColor));
    this.setChipMinHeight(a.getDimension(styleable.ChipDrawable_chipMinHeight, 0.0F));
    this.setChipCornerRadius(a.getDimension(styleable.ChipDrawable_chipCornerRadius, 0.0F));
    this.setChipStrokeColor(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_chipStrokeColor));
    this.setChipStrokeWidth(a.getDimension(styleable.ChipDrawable_chipStrokeWidth, 0.0F));
    this.setRippleColor(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_rippleColor));
    this.setChipText(a.getText(styleable.ChipDrawable_chipText));
    this.setTextAppearance(MaterialResources.getTextAppearance(this.context, a, styleable.ChipDrawable_android_textAppearance));
    this.setChipIconEnabled(a.getBoolean(styleable.ChipDrawable_chipIconEnabled, false));
    this.setChipIcon(MaterialResources.getDrawable(this.context, a, styleable.ChipDrawable_chipIcon));
    this.setChipIconSize(a.getDimension(styleable.ChipDrawable_chipIconSize, 0.0F));
    this.setCloseIconEnabled(a.getBoolean(styleable.**ChipDrawable_closeIconEnabled**, false));
    this.setCloseIcon(MaterialResources.getDrawable(this.context, a, styleable.ChipDrawable_closeIcon));
    this.setCloseIconTint(MaterialResources.getColorStateList(this.context, a, styleable.ChipDrawable_closeIconTint));
    this.setCloseIconSize(a.getDimension(styleable.ChipDrawable_closeIconSize, 0.0F));
    this.setCheckable(a.getBoolean(styleable.ChipDrawable_android_checkable, false));
    this.setCheckedIconEnabled(a.getBoolean(styleable.ChipDrawable_checkedIconEnabled, false));
    this.setCheckedIcon(MaterialResources.getDrawable(this.context, a, styleable.ChipDrawable_checkedIcon));
    this.setShowMotionSpec(MotionSpec.createFromAttribute(this.context, a, styleable.ChipDrawable_showMotionSpec));
    this.setHideMotionSpec(MotionSpec.createFromAttribute(this.context, a, styleable.ChipDrawable_hideMotionSpec));
    this.setChipStartPadding(a.getDimension(styleable.ChipDrawable_chipStartPadding, 0.0F));
    this.setIconStartPadding(a.getDimension(styleable.ChipDrawable_iconStartPadding, 0.0F));
    this.setIconEndPadding(a.getDimension(styleable.ChipDrawable_iconEndPadding, 0.0F));
    this.setTextStartPadding(a.getDimension(styleable.ChipDrawable_textStartPadding, 0.0F));
    this.setTextEndPadding(a.getDimension(styleable.ChipDrawable_textEndPadding, 0.0F));
    this.setCloseIconStartPadding(a.getDimension(styleable.ChipDrawable_closeIconStartPadding, 0.0F));
    this.setCloseIconEndPadding(a.getDimension(styleable.ChipDrawable_closeIconEndPadding, 0.0F));
    this.setChipEndPadding(a.getDimension(styleable.ChipDrawable_chipEndPadding, 0.0F));
    a.recycle();
}

它提供了类似的东西

                                     Table "public.t"
 Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description 
--------+---------+-----------+----------+---------+----------+--------------+-------------
 x      | integer |           |          |         | plain    |              | 
 y      | text    |           |          |         | extended |              | 

 x | y 
---+---
 1 | a
(1 row)

                                                           Table "public.foo"
   Column   |           Type           | Collation | Nullable |             Default              | Storage | Stats target | Description 
------------+--------------------------+-----------+----------+----------------------------------+---------+--------------+-------------
 i          | integer                  |           | not null | generated by default as identity | plain   |              | 
 data       | numeric                  |           |          |                                  | main    |              | 
 created_at | timestamp with time zone |           |          |                                  | plain   |              | 
Indexes:
    "foo_pkey" PRIMARY KEY, btree (i)

 i  |        data        |          created_at           
----+--------------------+-------------------------------
  1 |  0.749826541636139 | 2018-09-01 02:26:07.183046+03
  2 |   0.85738476132974 | 2018-09-01 02:26:07.183046+03
  3 |  0.814507594332099 | 2018-09-01 02:26:07.183046+03
  4 |  0.707018708344549 | 2018-09-01 02:26:07.183046+03
  5 |  0.523847402073443 | 2018-09-01 02:26:07.183046+03
  6 | 0.0278508486226201 | 2018-09-01 02:26:07.183046+03
  7 |  0.111673643812537 | 2018-09-01 02:26:07.183046+03
  8 | 0.0430165408179164 | 2018-09-01 02:26:07.183046+03
  9 |  0.358260124456137 | 2018-09-01 02:26:07.183046+03
 10 |  0.915565127041191 | 2018-09-01 02:26:07.183046+03
(10 rows)