Get all sequences with current values

GammaGames

I have the following query that gets all sequences and their schemas:

SELECT sequence_schema as schema, sequence_name as sequence
FROM information_schema.sequences
WHERE sequence_schema NOT IN ('topology', 'tiger')
ORDER BY 1, 2

I would like to get the current value of each sequence name with something like select last_value from [sequence];. I have tried the following (and a couple variations), but it doesn't work because the syntax isn't correct:

DO $$
BEGIN
    EXECUTE 
        sequence_schema as schema,
        sequence_name as sequence,
        last_value
    FROM information_schema.sequences
    LEFT JOIN (
        EXECUTE 'SELECT last_value FROM ' || schema || '.' || sequence
    ) tmp
    ORDER BY 1, 2;
END
$$;

I've found some solutions that create functions to execute text or piece together a query inside a function and return the result, but I would prefer to have a single query that I can run and modify however I like.

a_horse_with_no_name

In Postgres 12, you can use pg_sequences:

select schemaname as schema, 
       sequencename as sequence, 
       last_value
from pg_sequences

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

오라클은 너무 느린 all_sequences SELECT * FROM

분류에서Dev

How to get all the keys values from Redis Cache in C#?

분류에서Dev

MongoDb query to get all values of variable in collection with a condition

분류에서Dev

How to get current logging formatter?

분류에서Dev

Get all values for a specific data attribute

분류에서Dev

Select All Values From Table That Match All Values of Subquery

분류에서Dev

How to get all the values of one column and calculate a total

분류에서Dev

if-check for all array values

분류에서Dev

List all dotfiles current directory using zsh

분류에서Dev

Get all values that are exclusively in one category

분류에서Dev

Is there a way to get the "current route" in Happstack?

분류에서Dev

How to get all values from a list?

분류에서Dev

How to get JSON response array all index values?

분류에서Dev

Get User Current City in Android

분류에서Dev

Knockout Select / Unselect all and get the selected row values

분류에서Dev

Knockout Select / Unselect all and get the selected row values

분류에서Dev

Not all code paths return a values

분류에서Dev

how to get all values of object via coffeescript?

분류에서Dev

how to sum up all values with same keys in an object inside an array and get their average

분류에서Dev

Get current top position of document

분류에서Dev

Subtract values only if all are numbers

분류에서Dev

Java: Writing out all N-bit sequences containing K 1s

분류에서Dev

Get current SensorEvent value

분류에서Dev

Magento - Get all products in the current category

분류에서Dev

Update all values in a DynamoDB attribute

분류에서Dev

Using Array Function to Alter Cell Values Based on Their Current Values?

분류에서Dev

SailsJS: beforeUpdate (Lifecycle callback), access current values

분류에서Dev

Sqlite Get counts of all distinct values across a row

분류에서Dev

How to get all values of objects inside array

Related 관련 기사

  1. 1

    오라클은 너무 느린 all_sequences SELECT * FROM

  2. 2

    How to get all the keys values from Redis Cache in C#?

  3. 3

    MongoDb query to get all values of variable in collection with a condition

  4. 4

    How to get current logging formatter?

  5. 5

    Get all values for a specific data attribute

  6. 6

    Select All Values From Table That Match All Values of Subquery

  7. 7

    How to get all the values of one column and calculate a total

  8. 8

    if-check for all array values

  9. 9

    List all dotfiles current directory using zsh

  10. 10

    Get all values that are exclusively in one category

  11. 11

    Is there a way to get the "current route" in Happstack?

  12. 12

    How to get all values from a list?

  13. 13

    How to get JSON response array all index values?

  14. 14

    Get User Current City in Android

  15. 15

    Knockout Select / Unselect all and get the selected row values

  16. 16

    Knockout Select / Unselect all and get the selected row values

  17. 17

    Not all code paths return a values

  18. 18

    how to get all values of object via coffeescript?

  19. 19

    how to sum up all values with same keys in an object inside an array and get their average

  20. 20

    Get current top position of document

  21. 21

    Subtract values only if all are numbers

  22. 22

    Java: Writing out all N-bit sequences containing K 1s

  23. 23

    Get current SensorEvent value

  24. 24

    Magento - Get all products in the current category

  25. 25

    Update all values in a DynamoDB attribute

  26. 26

    Using Array Function to Alter Cell Values Based on Their Current Values?

  27. 27

    SailsJS: beforeUpdate (Lifecycle callback), access current values

  28. 28

    Sqlite Get counts of all distinct values across a row

  29. 29

    How to get all values of objects inside array

뜨겁다태그

보관