postgresql-9.2

How to Disconnect from a database and go back to the default database in PostgreSQL?

只愿长相守 提交于 2019-12-04 07:56:07
问题 I'm using PostgreSql version : postgres=# select version(); version ------------------------------------------------------------- PostgreSQL 9.2.4, compiled by Visual C++ build 1600, 64-bit (1 row) i had connected to a database from postgres=# to newdb=# .... Now i'm in newdb=# Database i want to disconnect it and go back to postgres=# database .... How to do this ? I have tried with disconnect newdb; but its giving erroe as:: postgres=# create database newdb; CREATE DATABASE postgres=# \c

cannot copy CSV into postgreSQL table : timestamp column won't accept the empty string

故事扮演 提交于 2019-12-04 05:27:34
I want to import a CSV file into version 9.2 but the CSV file has double-quote double-quote in the final column position to represent a NULL value: "2","1001","9","2","0","0","130","","2012-10-22 09:33:07.073000000","" which is mapped to a column of type Timestamp. postgreSQL doesn't like the "". I've tried to set the NULL option but maybe I'm not doing it correctly? I've tried NULL as '"" and NULL '' and NULL as '' and NULL "" but without success; here's my command: COPY SCH.DEPTS FROM 'H:/backups/DEPTS.csv' WITH ( FORMAT CSV, DELIMITER ',' , NULL '', HEADER TRUE, QUOTE '"' ) but it fails

Check for value with current_setting()

你离开我真会死。 提交于 2019-12-03 22:30:24
I'm trying to work with current_setting() . I came up with this: CREATE OR REPLACE FUNCTION process_audit() RETURNS TRIGGER AS $audit$ DECLARE user_id integer; BEGIN BEGIN user_id := current_setting('hws.current_user_id'); EXCEPTION WHEN OTHERS THEN user_id := NULL; END; ... RETURN NULL; END; $audit$ LANGUAGE plpgsql; The setting is set via: SELECT set_config('hws.current_user_id', '5', true); -- true = local setting -> only visible in current transaction The problem is, that current_setting() throws an exception if the value is not valid. I don't want to use EXCEPTION because I read that

How to count number of digits in Postgres integer data type?

荒凉一梦 提交于 2019-12-03 20:57:27
I need to restrict the number of digits in the 'integer' type fields to 6 or 7 in postgres. Basically it should accept 123456 or 1234567 but it should not accept 12345 or 12345678. How can I achieve this?? Have a check constraint with check (value>99999 and value<=9999999) You can use floor(log(i)+1 to get the number of digits in a number (that's base10 log). DB> CREATE TEMP TABLE t ( i integer CONSTRAINT i_has_6_or_7_digits CHECK (floor(log(abs(i))+1) BETWEEN 6 AND 7) ); CREATE TABLE Time: 5,676 ms DB> INSERT INTO t VALUES (123456), (1234567); INSERT 0 2 Time: 0,471 ms DB> INSERT INTO t

How to alter owner of a function in postgres

冷暖自知 提交于 2019-12-03 16:16:32
I am writing a script to alter all functions of postgres(changing owner of each function). I am able to list down all the function names using postgres query but not able to list parameters for each of those functions. My problem will be resolved if I get solution for any of the below mentioned problems: Is there any way to list down parameters' data type in each of the function. Do we have any approach to alter functions where instead of passing parameter type can I send some wild card. For Example can I write ALTER FUNCTION schemaname.func(text) OWNER TO 'newowner' as : ALTER FUNCTION

How do i create postgres to oracle dblink?

会有一股神秘感。 提交于 2019-12-03 14:18:45
How do I create dblink in postgres 9.2 ? I want to be able to use it using @ link in oracle? I am using postgres 9.2 64bit. DBlink is from postgres 9.2 to Oracle 11g. If you need to access postgresql FROM Oracle: http://dbaspot.wordpress.com/2013/05/29/how-to-access-postgresql-from-oracle-database/ If you need to access Oracle FROM postgresql: http://pgxn.org/dist/oracle_fdw/ 来源: https://stackoverflow.com/questions/18998225/how-do-i-create-postgres-to-oracle-dblink

Postgres nested JSON array using row_to_json

╄→гoц情女王★ 提交于 2019-12-03 12:16:56
I am trying to create nested json array using 2 tables. I have 2 tables journal and journaldetail. Schema is - journal : journalid, totalamount journaldetail : journaldetailid, journalidfk, account, amount Relation between journal and journaldetail is one-to-many. I want the output in following format : { journalid : 1, totalamount : 1000, journaldetails : [ { journaldetailid : j1, account : "abc", amount : 500 }, { journaldetailid : j2, account : "def", amount : 500 } ]} However, by writing this query as per this post the query is: select j.*, row_to_json(jd) as journal from journal j inner

how to change PostgreSQL data directory?

大城市里の小女人 提交于 2019-12-03 08:51:48
I am having a problem changing the data directory on postgresql 9.2 on windows7: i`m trying to change my data directory: how can i change data directory on postgreSQL with pgAdmin? This not possible from within pgAdmin (or any other SQL client because you need to stop the Postgres server in order to move the data directory) To move the directory, use these steps: Stop Postgres (you can use the control panel to find the correct service name) net stop <name_of_the_service> Make sure Postgres is not running (e.g. using ProcessMonitor) Remove the Windows service using pg_ctl unregister -N <name_of

Entity Framework 5.0 PostgreSQL (Npgsql) default connection factory

烂漫一生 提交于 2019-12-03 06:30:33
I'm trying to get EF 5.0 code first working with PostgreSQL (Npgsql provider). I have Npgsql 2.0.12.1 installed via NuGet (referenced assembly is 2.0.12.0 though). I have Npgsql declared in app.config (both default connection factory and provider factory): <entityFramework> <defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql, Version=2.0.12.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" /> </entityFramework> <system.data> <DbProviderFactories> <add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" support="FF" type="Npgsql.NpgsqlFactory,

Postgres DB Size Command

纵然是瞬间 提交于 2019-12-03 01:30:52
问题 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'); 回答1: 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