Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2009
    Posts
    2

    Unanswered: Copy rows of data into another table

    Hi,

    bare with me as im a bit of newbie, im trying to copy a large amount of data rows from 1 table into another table.

    Both tables have the exact same columns and are in the same databases

    pokerhand_id, playerhand_id, handtimestamp, gametype_id, player_id,
    numberofplayers, positiontype_id, holecard1int, holecard2int,
    holecardvalue_id, rakeamount, netamountwon, streetwentallin,
    didvpip, didpfr, preflopaction_id, firstpreflopactiontype_id,
    maxstreetseen, totalflopbets, totalflopcalls, totalturnbets,
    totalturncalls, totalriverbets, totalrivercalls, preflopplayeractiontype_id,
    flopcbetpossible, flopcbetmade, flopfacingcbet, flopfoldedtocbet,
    flopplayeractiontype_id, turncbetpossible, turncbetmade, turnfacingcbet,
    turnfoldedtocbet, turnplayeractiontype_id, rivercbetpossible,
    rivercbetmade, riverfacingcbet, riverfoldedtocbet, riverplayeractiontype_id,
    holecard3int, holecard4int, tscrec

    FROM playerhandscashkeycolumns;


    Now i want to copy all the data where player_id = 1,2,3,4,5,6,7 etc from one table into another table. there is about 20-30 player ids so rather than do the code 20-30 times id like to be able to just insert the 20-30 player_id's into the code

    I want to run the query through the PostgreSQL query tool in PGadmin.


    So i want to copy all the details from TABLE 1 where Player_id = x INTO Table 2.

    Any ideas how i do it as i have no PostgreSQL SQL experience.

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Something like this:
    Code:
    INSERT INTO the_new_table_with_no_name
    (  pokerhand_id,
       playerhand_id,
       handtimestamp,
       gametype_id,
       player_id,
       numberofplayers,
       positiontype_id,
       holecard1int,
       holecard2int,
       holecardvalue_id,
       rakeamount,
       netamountwon,
       streetwentallin,
       didvpip,
       didpfr,
       preflopaction_id,
       firstpreflopactiontype_id,
       maxstreetseen,
       totalflopbets,
       totalflopcalls,
       totalturnbets,
       totalturncalls,
       totalriverbets,
       totalrivercalls,
       preflopplayeractiontype_id,
       flopcbetpossible,
       flopcbetmade,
       flopfacingcbet,
       flopfoldedtocbet,
       flopplayeractiontype_id,
       turncbetpossible,
       turncbetmade,
       turnfacingcbet,
       turnfoldedtocbet,
       turnplayeractiontype_id,
       rivercbetpossible,
       rivercbetmade,
       riverfacingcbet,
       riverfoldedtocbet,
       riverplayeractiontype_id,
       holecard3int,
       holecard4int,
       tscrec)
    SELECT pokerhand_id,
           playerhand_id,
           handtimestamp,
           gametype_id,
           player_id,
           numberofplayers,
           positiontype_id,
           holecard1int,
           holecard2int,
           holecardvalue_id,
           rakeamount,
           netamountwon,
           streetwentallin,
           didvpip,
           didpfr,
           preflopaction_id,
           firstpreflopactiontype_id,
           maxstreetseen,
           totalflopbets,
           totalflopcalls,
           totalturnbets,
           totalturncalls,
           totalriverbets,
           totalrivercalls,
           preflopplayeractiontype_id,
           flopcbetpossible,
           flopcbetmade,
           flopfacingcbet,
           flopfoldedtocbet,
           flopplayeractiontype_id,
           turncbetpossible,
           turncbetmade,
           turnfacingcbet,
           turnfoldedtocbet,
           turnplayeractiontype_id,
           rivercbetpossible,
           rivercbetmade,
           riverfacingcbet,
           riverfoldedtocbet,
           riverplayeractiontype_id,
           holecard3int,
           holecard4int,
           tscrec
    FROM playerhandscashkeycolumns
    WHERE player_id IN (1,2,3,4,5,6,7,...)
    I urge you to to read the tutorial in the PostgreSQL manual if you plan to do work with SQL

  3. #3
    Join Date
    Aug 2009
    Location
    Olympia, WA
    Posts
    337
    If you are less of a purist than Shammat, you can skip a lot of typing since the table structures are identical
    Code:
    INSERT INTO new_table
    SELECT * FROM old_table
    WHERE player_id IN (1,2,3,4,5,6,7,...)
    Additionally you can make the target table on the fly like so
    Code:
    CREATE TABLE new_table AS
    SELECT * FROM old_table
    WHERE player_id IN (1,2,3,4,5,6,7,...)

  4. #4
    Join Date
    Aug 2010
    Posts
    14

    try this

    insert into newtable (column1, column1.....column n) select column1, column2.......column n from old table;

  5. #5
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by sahendramansingh View Post
    insert into newtable (column1, column1.....column n) select column1, column2.......column n from old table;
    Which is exactly what artacus72 and I have already posted, why do you repeat the solution?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •