postgresql-9.2

Can't log into system user postgres

社会主义新天地 提交于 2019-12-02 20:49:21
I installed postgresql on mac using brew. I wasn't asked about for the password for postgresql during the installation. Now I need to create a user and can't: Alexs-MacBook-Air:mydir alex$ su - postgres Password: su: Sorry Whatever password (including empty) I use, it is wrong. What's the easiest way to reset it? Craig Ringer You're trying to access the system user named postgres . According to comments you left on the other answers, there is no such user. You can't change the password of a user that doesn't exist. Perhaps it's _postgres or postgres_ ? I know some installers on OS X use weird

Postgres DB Size Command

放肆的年华 提交于 2019-12-02 13:48:00
Is there any command to find all the databases size in Postgres? I am able to find the size of a specific database by using following command: select pg_database_size('databaseName'); And... If in case you may not want to type a whole query... you can also type... \l+ <database_name> and you will get some details about the database, including the size of the database. And... To get sizes of all databases. you can just type... \l+ You may need to go into the postgresql command prompt to query with these postgresql helper commands. Check other postgresql helper commands by typing \? at the

Cancel previous operations in user defined function

别来无恙 提交于 2019-12-02 03:29:12
问题 Is it possible to cancel previous operations in a user defined function? For example: CREATE OR REPLACE FUNCTION transact_test () RETURNS BOOLEAN AS $$ BEGIN UPDATE table1 SET ... UPDATE table2 SET ... IF some_condition THEN --Here is possible to cancel all above operations? RETURN FALSE; END IF; RETURN TRUE; END; $$ LANGUAGE plpgsql; 回答1: Both answers so far are incorrect. If you try to start a transaction or use a SAVEPOINT inside a plpgsql function you get an error message like this: ERROR

What is the equivalent of regexp \\Q…\\E in postgresql?

老子叫甜甜 提交于 2019-12-02 00:17:23
I have the following query: SELECT field FROM myTable WHERE field ~ '\\Qprefix[\\E.+' It won't find values like prefix[foo] . How can I replace \Q..\E ? This form of regex with a \Q..\E unquoted substring is only supported by PCRE , which is not available natively in PostgreSQL. If your program must deal with this syntax in general, the PCRE support can be installed as an extension, as provided here: https://github.com/petere/pgpcre On the other hand, if it's only that one regex that should be made to work, first note that the double backslashes in '\\Qprefix[\\E.+' means literally two

Retrieve last known value for each column of a row

拈花ヽ惹草 提交于 2019-12-01 23:48:36
问题 Not sure about the correct words to ask this question, so I will break it down. I have a table as follows: date_time | a | b | c Last 4 rows: 15/10/2013 11:45:00 | null | 'timtim' | 'fred' 15/10/2013 13:00:00 | 'tune' | 'reco' | null 16/10/2013 12:00:00 | 'abc' | null | null 16/10/2013 13:00:00 | null | 'died' | null How would I get the last record but with the value ignoring the null and instead get the value from the previous record. In my provided example the row returned would be 16/10

how rails “update” multiple columns correctly - (updated_at should be updated as well)

最后都变了- 提交于 2019-12-01 23:32:43
问题 I am having trouble updating multiple columns properly with rails activerecords. I want to use something like update which basically gets updated_at updated, but i just cant pass multiple column. I could use update_all but it doesnt update updated_at with the current timestamp. Here's what i'ved tried: this doesnt work: (only takes in payment_total but not the rest) retval = @invoice.update(:payment_total => 20, :due_amount => 10, :data => clonedata.to_json) :data - this is actually a json

Cancel previous operations in user defined function

拈花ヽ惹草 提交于 2019-12-01 23:01:31
Is it possible to cancel previous operations in a user defined function? For example: CREATE OR REPLACE FUNCTION transact_test () RETURNS BOOLEAN AS $$ BEGIN UPDATE table1 SET ... UPDATE table2 SET ... IF some_condition THEN --Here is possible to cancel all above operations? RETURN FALSE; END IF; RETURN TRUE; END; $$ LANGUAGE plpgsql; Both answers so far are incorrect. If you try to start a transaction or use a SAVEPOINT inside a plpgsql function you get an error message like this: ERROR: cannot begin/end transactions in PL/pgSQL HINT: Use a BEGIN block with an EXCEPTION clause instead.

How to find whether unique key constraint exists for given columns

纵然是瞬间 提交于 2019-12-01 22:51:25
问题 I am working on a perl script, where i need to run update queries. But I need to check if the update sql command does not violate unique key constraint. So if I have a table tb(C1,C2,C3) and my update query is like: update tb set C1='b1' where C2='a1' ; Is there a way to find if a unique key constraint exist for column C1,C2 before trying to update? Ie: UNIQUE(C1,C2) . 回答1: You can query the system catalogs for unique constraints , in particular pg_constraint and pg_attribute : SELECT c

How to find whether unique key constraint exists for given columns

故事扮演 提交于 2019-12-01 21:54:53
I am working on a perl script, where i need to run update queries. But I need to check if the update sql command does not violate unique key constraint. So if I have a table tb(C1,C2,C3) and my update query is like: update tb set C1='b1' where C2='a1' ; Is there a way to find if a unique key constraint exist for column C1,C2 before trying to update? Ie: UNIQUE(C1,C2) . You can query the system catalogs for unique constraints , in particular pg_constraint and pg_attribute : SELECT c.conname, pg_get_constraintdef(c.oid) FROM pg_constraint c JOIN ( SELECT array_agg(attnum::int) AS attkey FROM pg

how rails “update” multiple columns correctly - (updated_at should be updated as well)

◇◆丶佛笑我妖孽 提交于 2019-12-01 21:46:45
I am having trouble updating multiple columns properly with rails activerecords. I want to use something like update which basically gets updated_at updated, but i just cant pass multiple column. I could use update_all but it doesnt update updated_at with the current timestamp. Here's what i'ved tried: this doesnt work: (only takes in payment_total but not the rest) retval = @invoice.update(:payment_total => 20, :due_amount => 10, :data => clonedata.to_json) :data - this is actually a json field output: nothing this works: retval = Invoice.where(:id => @invoice.id).update_all(:payment_total =>