select into with a constraint id postgres

goku

I have the following table images

id,image,download,type
1,url1,0,'extra'
2,url2,0,'main'
3,url3,1,'extra'

I am copying some of it's data for testing purposes into temp1 and giving the id "p_key" using

select * into temp1 from images where download=0 order by id offset 0 limit 1000000; then

alter table temp1 add constraint temp1_pk primary key (id);

is there a way of combining the two commands into 1 command?

Laurenz Albe

There is no need to combine these two statements into one, and from a performance perspective it is preferrable to add the constraint after you insert the data.

So execute both statements in a single transaction, and you will have all the benefits of combining the statements:

BEGIN;
/* your statements */
COMMIT;

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

SQLAlchemy select with where constraint

分類Dev

SQLAlchemy select with where constraint

分類Dev

Cannot find constraint by id

分類Dev

Postgres SQL Exclusive OR (XOR) CHECK CONSTRAINT, is it possible?

分類Dev

Postgres Set Select Value In If

分類Dev

use select statement in oracle check constraint

分類Dev

How to return original row in Postgres upon violating a unique constraint

分類Dev

Postgres constraint name need to be unique across single table or entire schema?

分類Dev

Postgres 9.5 ON CONFLICT DO SELECT

分類Dev

Inserting into array on SELECT at index in Postgres

分類Dev

Postgres SELECT COUNT ...更新用

分類Dev

Select id based on label

分類Dev

ID を持つエントリが存在するテーブルからの Postgres SQL SELECT データ

分類Dev

NOT NULL constraint failed: cars_car.owner_id

分類Dev

NOT NULL constraint failed: portal_visitrequests.visitor_id

分類Dev

NOT NULL constraint failed: users_details.user_id

分類Dev

Postgres table select query is too slow

分類Dev

Postgres upsert using results from select

分類Dev

select alternate field name group by postgres

分類Dev

select alternate field name group by postgres

分類Dev

postgres SELECT query returns unusable result

分類Dev

How to select rows by year interval with postgres sql?

分類Dev

SQL:SELECT date BETWEEN error(postgres)

分類Dev

Postgres SELECT DISTINCT、最高値のみ

分類Dev

nodejs & postgres : best way to do select for update

分類Dev

How to select the reserved word (limit) in postgres

分類Dev

Duplicate key value violates unique constraint "hibernate_sequences_pkey" exception by Postgres

分類Dev

postgresで動作したMySQLのCONSTRAINTでの構文エラー

分類Dev

Mybatis Generator Postgres return created id support

Related 関連記事

  1. 1

    SQLAlchemy select with where constraint

  2. 2

    SQLAlchemy select with where constraint

  3. 3

    Cannot find constraint by id

  4. 4

    Postgres SQL Exclusive OR (XOR) CHECK CONSTRAINT, is it possible?

  5. 5

    Postgres Set Select Value In If

  6. 6

    use select statement in oracle check constraint

  7. 7

    How to return original row in Postgres upon violating a unique constraint

  8. 8

    Postgres constraint name need to be unique across single table or entire schema?

  9. 9

    Postgres 9.5 ON CONFLICT DO SELECT

  10. 10

    Inserting into array on SELECT at index in Postgres

  11. 11

    Postgres SELECT COUNT ...更新用

  12. 12

    Select id based on label

  13. 13

    ID を持つエントリが存在するテーブルからの Postgres SQL SELECT データ

  14. 14

    NOT NULL constraint failed: cars_car.owner_id

  15. 15

    NOT NULL constraint failed: portal_visitrequests.visitor_id

  16. 16

    NOT NULL constraint failed: users_details.user_id

  17. 17

    Postgres table select query is too slow

  18. 18

    Postgres upsert using results from select

  19. 19

    select alternate field name group by postgres

  20. 20

    select alternate field name group by postgres

  21. 21

    postgres SELECT query returns unusable result

  22. 22

    How to select rows by year interval with postgres sql?

  23. 23

    SQL:SELECT date BETWEEN error(postgres)

  24. 24

    Postgres SELECT DISTINCT、最高値のみ

  25. 25

    nodejs & postgres : best way to do select for update

  26. 26

    How to select the reserved word (limit) in postgres

  27. 27

    Duplicate key value violates unique constraint "hibernate_sequences_pkey" exception by Postgres

  28. 28

    postgresで動作したMySQLのCONSTRAINTでの構文エラー

  29. 29

    Mybatis Generator Postgres return created id support

ホットタグ

アーカイブ