Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PostGreSQL: Help - How to replace characters in dblink?

    Hi, I wanted to copy a data from table1 in db1 to table2 in db2, which has the same structure, with the PosgreSQL dblink funtion.

    The fields for both the tables are: id, first_name, last_name.

    However, I would like to replace the id and first_name in table1 to: 3 and 'nil' to insert into table2.

    INSERT INTO table2 SELECT * FROM dblink('dbname=db1', 'SELECT 3, nil, last_name FROM table1 WHERE id = 1000') AS t1(id integer, first_name varchar, last_name varchar);

    The id can be replaced but it thought "nil" is a column name, instead of the value that I wanted to replace the first_name with, thus return error.

    Anyone knows how to replace characters in dblink or any solution to this problem??
    Thanks in advance!

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,631
    Thanks
    4
    Thanked 147 Times in 138 Posts
    enclose it in quotes.

  • #3
    New Coder
    Join Date
    Dec 2005
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had tried that but PostGreSQL recognize it as a column


  •  

    Posting Permissions

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