Automatically populate a timestamp field in PostgreSQL when a new row is inserted

To populate the column during insert, use a DEFAULT value: CREATE TABLE users ( id serial not null, firstname varchar(100), middlename varchar(100), lastname varchar(100), email varchar(200), timestamp timestamp default current_timestamp ) Note that the value for that column can explicitly be overwritten by supplying a value in the INSERT statement. If you want to prevent … Read more

“column not allowed here” error in INSERT statement

You’re missing quotes around the first value, it should be INSERT INTO LOCATION VALUES(‘PQ95VM’, ‘HAPPY_STREET’, ‘FRANCE’); Incidentally, you’d be well-advised to specify the column names explicitly in the INSERT, for reasons of readability, maintainability and robustness, i.e. INSERT INTO LOCATION (POSTCODE, STREET_NAME, CITY) VALUES (‘PQ95VM’, ‘HAPPY_STREET’, ‘FRANCE’);

Cannot INSERT: ERROR: array value must start with “{” or dimension information

Your column username seems to be an array type, so the literal ‘mahman’ is not valid input for it. It would have to be ‘{mahman}’: INSERT INTO user_data.user_data (username,randomint) VALUES (‘{mahman}’,1); (Or make it a plain varchar column or text column instead.) Update confirms it: character varying(50)[] is an array of character varying(50). About array … Read more

Is there any way to show progress on a `gunzip < database.sql.gz | mysql ...` process?

You may use -v : Verbose mode (show progress) in your command, or there’s another method using Pipe Viewer (pv) which shows the progress of the gzip, gunzip command as follows: $ pv database1.sql.gz | gunzip | mysql -u root -p database1 This will output progress similar to scp: $ pv database1.sql.gz | gunzip | … Read more

How does COPY work and why is it so much faster than INSERT?

There are a number of factors at work here: Network latency and round-trip delays Per-statement overheads in PostgreSQL Context switches and scheduler delays COMMIT costs, if for people doing one commit per insert (you aren’t) COPY-specific optimisations for bulk loading Network latency If the server is remote, you might be “paying” a per-statement fixed time … Read more