• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Desperately seeking SQL"

Collapse

  • Sysman
    replied
    Sorry, missed this one earlier.

    For future reference type this at this PSQL prompt:

    \h copy

    more generally:

    '\h' gives help on SQL syntax
    '\?' gives help on connecting to the database, changing directory etc.

    Leave a comment:


  • Cliphead
    replied
    I got it! Outstanding help guys

    Leave a comment:


  • thunderlizard
    replied
    For a one-off like this I'd probably put the list of code numbers into Excel column A.
    Then in cell B1, something like =CONCATENATE("insert into shop_upgradecode (ProductID,Code,Is_BlackListed,was_used) values (17, '", A1, "', false, false);")

    then fill down column B.
    Then copy the 1800 INSERT statements into your SQL editor and run them in. 18000 should give you just enough time to get a cup of tea while it runs.

    (I've used Oracle syntax - postgresql might be different)

    Leave a comment:


  • Weltchy
    replied
    Originally posted by Cliphead View Post
    I have a text file with all the code numbers in a list, it will be a one off import of that list and then left alone.

    I'm assuming that

    INSERT VALUES (ProductID,Code,Is_BlackListed,was_used)
    SELECT 17,[Code],0,0 FROM ImportedCodeData <----------this is the text file?
    The ImportedCodeData should be the resulting table from the CSV File import. Take a look at http://www.ensode.net/postgresql_csv_import.html which uses the copy command to transfer data from a CSV file into a temporarily created table.

    I would try something like

    create table ImportedCodeData(Code varchar(500));
    copy ImportedCodeData from '/path/to/csv/codes.txt' DELIMITERS ',' CSV;

    This should get the data into the ImportedCodeData table, after which you can insert the data using the original statement

    As I said though, its all pure guesswork from me as I don't use POSTGRESQL!

    Leave a comment:


  • Cliphead
    replied
    Originally posted by Weltchy View Post
    I don't personally work with Posgtresql, but are the code numbers held in say a spreadsheet or something?

    If so, I would look to manually import the data and then use something like

    INSERT VALUES (ProductID,Code,Is_BlackListed,was_used)
    SELECT 17,[Code],0,0 FROM ImportedCodeData

    This assumes the import is a once off and you don't want to parameterise and put the sql into a stored proc or something?

    Also, most sql databases stored boolean fields as BIT, hence the 0 for is_blacklisted and was_used. As I'm not familiar with Posgtresql, the data type of BOOLEAN might be valid and could take false instead
    I have a text file with all the code numbers in a list, it will be a one off import of that list and then left alone.

    I'm assuming that

    INSERT VALUES (ProductID,Code,Is_BlackListed,was_used)
    SELECT 17,[Code],0,0 FROM ImportedCodeData <----------this is the text file?

    Leave a comment:


  • Weltchy
    replied
    I don't personally work with Posgtresql, but are the code numbers held in say a spreadsheet or something?

    If so, I would look to manually import the data and then use something like

    INSERT VALUES (ProductID,Code,Is_BlackListed,was_used)
    SELECT 17,[Code],0,0 FROM ImportedCodeData

    This assumes the import is a once off and you don't want to parameterise and put the sql into a stored proc or something?

    Also, most sql databases stored boolean fields as BIT, hence the 0 for is_blacklisted and was_used. As I'm not familiar with Posgtresql, the data type of BOOLEAN might be valid and could take false instead

    Leave a comment:


  • Cliphead
    started a topic Desperately seeking SQL

    Desperately seeking SQL

    Guys, been left in the lurch since the developer responsible has buggered off on holiday for five weeks. I need to get this done as soon as possible but I know very little about SQL.

    Here's the scenario. Posgtresql database and one of the tables (shop_upgradecode), has this structure;

    id integer
    NOT NULL
    nextval('shop_upgradecode_id_seq'::regclass)

    product_id integer
    NOT NULL

    code character varying(500)
    NOT NULL [uniq]

    is_blacklisted boolean
    NOT NULL

    was_used boolean
    NOT NULL

    product_id will be 17

    code is a list of 18,000 numbers like this 71938-47183-31335-71295-33203

    is_blacklisted will be false

    was_used will be false

    What I have is a list of the code numbers that I need to get into the table but I haven't got a clue where to start. I would seriously appreciate any help to get this job done, kinda crucial to our operation.
Working...
X