postgresql-9.3

Equivalent or alternative method for RAISE EXCEPTION statement for function in LANGUAGE sql?

我们两清 提交于 2021-02-17 06:59:41
问题 Is there an equivalent (or workaround) for the RAISE EXCEPTION statement for the function written below in LANGUAGE sql ? CREATE OR REPLACE FUNCTION fn_interpolation (p_yearinteger integer, p_admin_id integer, p_crop_id integer, p_cropparameter integer) RETURNS TABLE (value double precision, remark text) AS $$ WITH yearvalues AS (SELECT yearinteger, value FROM cropvalues WHERE crops_id = p_crop_id AND admin_id = p_admin_id AND parameter_id = p_cropparameter), I need the function to abort and

PostgreSQL: How escape '?

半腔热情 提交于 2021-02-17 06:53:05
问题 My original sql: INSERT INTO clients (name, phone) VALUES ('Vs'emandon', '333026660'); I read about E'' and tried this: INSERT INTO clients (name) VALUES ('VsE'''emandon); But this not working. http://www.sqlfiddle.com/#!15/f717e/2 回答1: Postgres follows the SQL standard. Quote from the manual: To include a single-quote character within a string constant, write two adjacent single quotes, e.g., 'Dianne''s horse' . Note that this is not the same as a double-quote character ( " ). INSERT INTO

How to read and insert bytea columns using psycopg2?

[亡魂溺海] 提交于 2021-02-16 16:17:04
问题 I am working on a Python script to replicate some Postgresql tables from one environment to another (which does a little more than pg_dump ). It works except when I am copying a table that has bytea data type. I read the source table data in memory, then I dump the memory in the target database with concatenated inserts. Here is my method that produces an insert statement: def generateInsert(self, argCachedRow): colOrd = 0; valClauseList = [] hasBinary = False for colData in argCachedRow:

Postgresql group by for multiple lines

℡╲_俬逩灬. 提交于 2021-01-29 09:03:04
问题 I have this table named hr_holidays_by_calendar . I just want to filter out the rows where the same employee is having two leaves in same day . Table hr_holidays_by_calendar : Query I tried: Wasn't anywhere near in solving this. select hol1.employee_id, hol1.leave_date, hol1.no_of_days, hol1.leave_state from hr_holidays_by_calendar hol1 inner join (select employee_id, leave_date from hr_holidays_by_calendar hol1 group by employee_id, leave_date having count(*)>1)sub on hol1.employee_id=sub

Postgresql Error: connection terminated

痞子三分冷 提交于 2021-01-27 10:44:24
问题 i have a simple application linked up to a postgres database. it reads about 30 rows of data when you load up the application. but every now an then it wont load and when i look at my server i have the error Error: connection terminated. usually if i load it up several times in a short space of time. does anyone know why this might be happening? am i working it too hard? the code is below: function getDB(callback){ console.log('inside getDB') Client.connect(function(err){ if(err){ return

Postgresql Error: connection terminated

三世轮回 提交于 2021-01-27 10:40:57
问题 i have a simple application linked up to a postgres database. it reads about 30 rows of data when you load up the application. but every now an then it wont load and when i look at my server i have the error Error: connection terminated. usually if i load it up several times in a short space of time. does anyone know why this might be happening? am i working it too hard? the code is below: function getDB(callback){ console.log('inside getDB') Client.connect(function(err){ if(err){ return

Why char datatype is converted to bpchar automatically?

99封情书 提交于 2020-07-08 07:22:08
问题 Is there any possible to convert CHAR datatype into bpchar automatically? We have seen the scenario which selected column datatype is CHAR from application end but database level bpchar got created. Can anyone help me on this? 回答1: https://www.postgresql.org/docs/current/static/datatype-character.html character(n), char(n) fixed-length, blank padded Effectively in bpchar b stands for blank and p stands for padded and bpchar is same as char(n) or character(n) , a blank padded to n length

How to cast varchar to boolean

烈酒焚心 提交于 2020-06-27 08:03:45
问题 I have a variable 'x' which is varchar in staging table, but it is set to boolean in target table which has 'true' and 'false' values. How can I convert varchar to boolean in postgresql? 回答1: If the varchar column contains one of the strings (case-insensitive): t , true , y , yes , on , 1 f , false , n , no , off , 0 you can simply cast it to boolean, e.g: select 'true'::boolean, 'false'::boolean; bool | bool ------+------ t | f (1 row) See SQLFiddle. 回答2: For Redshift, I had the best luck

How to cast varchar to boolean

萝らか妹 提交于 2020-06-27 08:03:41
问题 I have a variable 'x' which is varchar in staging table, but it is set to boolean in target table which has 'true' and 'false' values. How can I convert varchar to boolean in postgresql? 回答1: If the varchar column contains one of the strings (case-insensitive): t , true , y , yes , on , 1 f , false , n , no , off , 0 you can simply cast it to boolean, e.g: select 'true'::boolean, 'false'::boolean; bool | bool ------+------ t | f (1 row) See SQLFiddle. 回答2: For Redshift, I had the best luck