Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2008
    Posts
    1

    Unanswered: use array in insert query

    hi

    i want to pass array in my table which contain two element.
    like

    INSERT INTO customer(cid, pid)VALUES (236,array[[2],[3]]);

    this query insert two row in my table like that

    cid pid

    236 2

    236 3

    but this query give the error


    ERROR: column "pid" is of type integer but expression is of type integer[]
    SQL state: 42804
    Hint: You will need to rewrite or cast the expression.

    i donot understand how to solve this problem


    thx
    gold18

  2. #2
    Join Date
    Nov 2006
    Posts
    82
    ?? i'm afraid postgres is not as smart as you wish. why do you want to use such syntax, it it is worth you can write a function doing what you want.
    in newest postgres you can use multiple inserts, but its syntax is diferent from yours.

  3. #3
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    The function could accept a single value and an array value and issue two inserts (using a single insert statement if you wish)

    BTW. pg's multi-insert is:
    Code:
    INSERT INTO customer(cid, pid) VALUES (236,2), (236,3)
    (I would assume that if you write the inserts as separate statements, you would probably want them inside a single transaction)
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Posting Permissions

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