postgresql-9.2

Count rows affected by DELETE

两盒软妹~` 提交于 2019-12-20 05:58:03
问题 I use this code to verify the DELETE sentence, but I am sure you know a better way: CREATE OR REPLACE FUNCTION my_schema.sp_delete_row_table(table_name character varying , id_column character varying , id_value integer) RETURNS integer AS $BODY$ DECLARE BEFORE_ROWS integer; AFTER_ROWS integer; BEGIN EXECUTE 'SELECT count(*) FROM ' || TABLE_NAME INTO BEFORE_ROWS; EXECUTE 'DELETE FROM ' || TABLE_NAME || ' WHERE ' || ID_COLUMN || ' = ' || (ID_VALUE)::varchar; EXECUTE 'SELECT count(*) FROM ' ||

ERROR: query has no destination for result data for FUNCTION returning a bigint

二次信任 提交于 2019-12-20 04:53:41
问题 There are many similar questions on SO about this error, but none seem to answer my case. I have created the following stored procedure in PostgreSql: CREATE OR REPLACE FUNCTION "MySchema".UserAccountInsert( id bigint, lang varchar(3), nname varchar(40), email varchar(40), email_conf boolean, status smallint, status_update bigint, creation bigint, preferences json) RETURNS bigint AS $BODY$ DECLARE rowc INTEGER; ret_id bigint; BEGIN SELECT "ID" FROM "MySchema"."USER_ACCOUNT" WHERE "ID" = id OR

Creating case-insensitive indexes on Postgres string array

为君一笑 提交于 2019-12-20 02:38:28
问题 I'm using a varchar[] column (varchar array) in Postgres 9.2 to store some tags. While retrieving rows by tags, I want the query to be case insensitive. However, I want to preserve the case to display in the UI (therefore I can't just store everything as lower case). So, my question is how do I create a case-insensitive index in Postgres over a varchar array? One possible approach would be to create a functional GIN index on the column. How does one do that? Any other approaches? 回答1:

Insert multiple rows where not exists PostgresQL

我与影子孤独终老i 提交于 2019-12-19 06:16:12
问题 I'd like to generate a single sql query to mass-insert a series of rows that don't exist on a table. My current setup makes a new query for each record insertion similar to the solution detailed in WHERE NOT EXISTS in PostgreSQL gives syntax error, but I'd like to move this to a single query to optimize performance since my current setup could generate several hundred queries at a time. Right now I'm trying something like the example I've added below: INSERT INTO users (first_name, last_name,

Alter default privileges for a group role in PostgreSQL

时间秒杀一切 提交于 2019-12-18 11:04:53
问题 I have created two group roles in Postgres 9.2: one is called admins and the other is called readers . The idea is very simple: admins create tables and readers have read access to these tables. After granting privileges to both group roles everything worked as expected for exisintg objects. But now what about new objects? So after reading this post I altered the default privileges to grant SELECT privileges to readers for any new table that admins create: ALTER DEFAULT PRIVILEGES FOR ROLE

Export and import table dump (.sql) using pgAdmin

流过昼夜 提交于 2019-12-18 09:57:19
问题 I have pgAdmin version 1.16.1 So, for exporting table dumm I do: Right click on table, then in menu click on backup , then in Format choice Plain and save file as some_name.sql Then I remove table. Ok, now I need import table backup some_name.sql into database. How to do this? I can't find how to import table's .sql dump into database using pgAdmin. Can you help me please? 回答1: In pgAdmin, select the required target scheme in object tree Click on Plugins/PSQL Console Write \i /path/to

Postgresql - unable to drop database because of some auto connections to DB

吃可爱长大的小学妹 提交于 2019-12-18 09:54:20
问题 Whenever I try to drop database I get: ERROR: database "pilot" is being accessed by other users DETAIL: There is 1 other session using the database. When I use: SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'TARGET_DB'; I terminated the connection from that DB, but if I try to drop database after that somehow someone automatically connects to that database and gives this error. What could be doing that? No one uses this database,

Connection refused (PGError) (postgresql and rails)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 03:59:04
问题 I keep getting this error when i try to run my localhost using "$rails s": (Mac OSX 10.8.3) (ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]) (Rails 3.2.11) (psql (PostgreSQL) 9.2.2 ) **installed with homebrew I have been doing a lot of uninstalling postgresql and reinstalling so I have a hunch that there may be conflicting libraries somewhere...i just dont know where to start. I had Postgresql 9.1 and 9.2 in the same folder and just moved 9.1 into the trash. Here is the

Connection refused (PGError) (postgresql and rails)

浪子不回头ぞ 提交于 2019-12-18 03:58:56
问题 I keep getting this error when i try to run my localhost using "$rails s": (Mac OSX 10.8.3) (ruby 2.0.0p195 (2013-05-14 revision 40734) [x86_64-darwin12.3.0]) (Rails 3.2.11) (psql (PostgreSQL) 9.2.2 ) **installed with homebrew I have been doing a lot of uninstalling postgresql and reinstalling so I have a hunch that there may be conflicting libraries somewhere...i just dont know where to start. I had Postgresql 9.1 and 9.2 in the same folder and just moved 9.1 into the trash. Here is the

Error: query has no destination for result data while using a cursor

我怕爱的太早我们不能终老 提交于 2019-12-17 21:10:26
问题 I have a function which I have written to automate the execution of a group of functions for my project. I am taking a refcursor where I am storing my required data which I will be passing as an argument to each of my functions being called and based on the argument will get executed. I am giving my code here: CREATE OR REPLACE FUNCTION ccdb.fn_automation() RETURNS void AS $BODY$ DECLARE sec_col refcursor; cnt integer; sec_code ccdb.update_qtable%ROWTYPE; new_cnt numeric; BEGIN SELECT COUNT(*