How Postgresql COPY TO STDIN With CSV do on conflic do update?

In this SO post, there are two answers that -combined together- provide a nice solution for successfully using ON CONFLICT. The example below, uses ON CONFLICT DO NOTHING;: BEGIN; CREATE TEMP TABLE tmp_table (LIKE main_table INCLUDING DEFAULTS) ON COMMIT DROP; COPY tmp_table FROM ‘full/file/name/here’; INSERT INTO main_table SELECT * FROM tmp_table ON CONFLICT DO NOTHING; … Read more

Python multiprocessing stdin input

When you take a look at Pythons implementation of multiprocessing.Process._bootstrap() you will see this: if sys.stdin is not None: try: sys.stdin.close() sys.stdin = open(os.devnull) except (OSError, ValueError): pass You can also confirm this by using: >>> import sys >>> import multiprocessing >>> def func(): … print(sys.stdin) … >>> p = multiprocessing.Process(target=func) >>> p.start() >>> <_io.TextIOWrapper … Read more

Reading from stdin

You can do something like this to read 10 bytes: char buffer[10]; read(STDIN_FILENO, buffer, 10); remember read() doesn’t add ‘\0′ to terminate to make it string (just gives raw buffer). To read 1 byte at a time: char ch; while(read(STDIN_FILENO, &ch, 1) > 0) { //do stuff } and don’t forget to #include <unistd.h>, STDIN_FILENO … Read more

Nodejs Child Process: write to stdin from an already initialised process

You need to pass also \n symbol to get your command work: var spawn = require(‘child_process’).spawn, child = spawn(‘phantomjs’); child.stdin.setEncoding(‘utf-8’); child.stdout.pipe(process.stdout); child.stdin.write(“console.log(‘Hello from PhantomJS’)\n”); child.stdin.end(); /// this call seems necessary, at least with plain node.js executable