postgresql-9.3

Is there any technique to do in postgresql 9.3 so that it start returning 1 and 0 instead of “t” and “f” for boolean type

一个人想着一个人 提交于 2019-12-02 01:54:05
问题 Actually i am migrating my ms sql server into postgresql 9.3 and we were using int data type to store 1 and 0 for boolean values but in postgresql9.3 it is not possible. what did i get when i did a little research on datatype of postgresql: In Postgresql:- For Integer type datatype:- insert into ask(aint) values(1) working insert into ask(aint) values('1') working insert into ask(aint) values(true) not working select * from ask where aint=1; working select * from ask where aint='1'; working

Why does this PostgreSQL transaction give “WARNING: there is no transaction in progress”

ε祈祈猫儿з 提交于 2019-12-02 01:16:50
I am running the transaction queries in code like this (simplified): try { runQuery("begin"); runQuery("some query ..."); runQuery("some other query ..."); runQuery("some more query ..."); runQuery("some extra query ..."); runQuery("commit"); } catch (e){ runQuery("rollback"); } Here is the list of statements from the postgres log file. Notice that first begin / commit works fine and the second commit gives the error mentioned in the subject: 2015-02-18 20:19:17 UTC [6459-7] vdsr@sails LOG: statement: begin 2015-02-18 20:19:17 UTC [6459-8] vdsr@sails LOG: execute <unnamed>: INSERT INTO "groups

@@ROWCOUNT in PostgreSQL 9.3

丶灬走出姿态 提交于 2019-12-01 17:08:27
I want to returns the number of rows affected by the last statement. Using Microsoft SQL Server 2008 R2 I do it this way: SELECT * FROM Test_table; SELECT @@ROWCOUNT AS [Number Of Rows Affected]; Will gives: Number Of Rows Affected ----------------------- 10 How about in PostgreSQL 9.3? AFAIK there is no such construct in postgresql however the number of rows is part of the result you get from postgresql. CORRECTION : as a_horse_with_no_name states in his comment there is something similar which can be used within PL/pgSQL. Also see example in answer posted by Achilles Ram Nakirekanti From

@@ROWCOUNT in PostgreSQL 9.3

时光毁灭记忆、已成空白 提交于 2019-12-01 16:27:03
问题 I want to returns the number of rows affected by the last statement. Using Microsoft SQL Server 2008 R2 I do it this way: SELECT * FROM Test_table; SELECT @@ROWCOUNT AS [Number Of Rows Affected]; Will gives: Number Of Rows Affected ----------------------- 10 How about in PostgreSQL 9.3? 回答1: AFAIK there is no such construct in postgresql however the number of rows is part of the result you get from postgresql. CORRECTION : as a_horse_with_no_name states in his comment there is something

how to parse json using json_populate_recordset in postgres

↘锁芯ラ 提交于 2019-12-01 16:03:11
I have a json stored as text in one of my database row. the json data is as following [{"id":67272,"name":"EE_Quick_Changes_J_UTP.xlsx"},{"id":67273,"name":"16167.txt"},{"id":67274,"name":"EE_12_09_2013_Bcum_Searchall.png"}] to parse this i want to use postgresql method json_populate_recordset() when I post a command like select json_populate_recordset(null::json,'[{"id":67272,"name":"EE_Quick_Changes_J_UTP.xlsx"},{"id":67273,"name":"16167.txt"},{"id":67274,"name":"EE_12_09_2013_Bcum_Searchall.png"}]') from anoop; it gives me following error first argument of json_populate_recordset must be a

Postgresql - INSERT RETURNING INTO ambiguous column reference

社会主义新天地 提交于 2019-12-01 14:20:52
Can someone politely explain this crazyness? INSERT INTO "dbo"."UserProfile" ("FirstName") VALUES('John') RETURNING "UserProfileId" INTO _UserProfileId; throws an ambiguous reference error, however this correctly executes: INSERT INTO "dbo"."UserProfile" ("FirstName") VALUES('John') RETURNING "dbo"."UserProfile"."UserProfileId" INTO _UserProfileId; _UserProfileId is a declared integer variable. I couldn't find any references to this syntax in the manual or why on earth this would be ambiguous in any way. Erwin Brandstetter IN and OUT parameters (including columns in RETURNS TABLE ) are visible

Grouped result insert into two tables

橙三吉。 提交于 2019-12-01 12:32:29
问题 I have the following table. CREATE TEMPORARY TABLE temp_detail ( purchase_order_detail_id INTEGER, item_id integer, qty numeric(18,2), project_id integer, category_id integer, supplier_id integer, rate numeric(18,2) ); I am getting the grouped result with ids using SELECT array_agg(purchase_order_detail_id), project_id, category_id, supplier_id FROM temp_detail GROUP BY project_id, category_id, supplier_id Now I want to insert project_id, category_id, supplier_id into a master table and item

Convert value from string representation in base N to numeric

主宰稳场 提交于 2019-12-01 10:36:17
On my database i keep a numbers in specific notation as varchar values. Is there any way to typecast this values into decimals with selected notation? What i basically looking here should look like this: SELECT to_integer_with_notation('d', '20') int4 --------- 13 One more example: SELECT to_integer_with_notation('d3', '23') int4 --------- 302 Unfortunately, there is no built-in function for that in PostgreSQL, but can be written fairly easy: CREATE OR REPLACE FUNCTION number_from_base(num TEXT, base INTEGER) RETURNS NUMERIC LANGUAGE sql IMMUTABLE STRICT AS $function$ SELECT sum(exp * cn) FROM

Pivot table for data per hour

守給你的承諾、 提交于 2019-12-01 09:50:42
问题 I want to display a pivot table for the given below records: I have a table called fooo with the two columns: create table fooo ( cola varchar(5), colb time ); Inserting some records: insert into fooo values ('a','10:00:00'), ('a','10:30:00'), ('b','20:00:00'), ('c','13:00:00') , ('d','01:00:00'), ('e','10:10:00'), ('f','02:01:00'), ('g','02:20:00') , ('h','04:00:00'), ('i','05:00:00'), ('j','06:00:00'), ('k','07:00:00') , ('l','08:00:00'), ('m','09:00:00'), ('n','22:00:00'), ('o','23:00:00')

Pivot table for data per hour

空扰寡人 提交于 2019-12-01 09:40:20
I want to display a pivot table for the given below records: I have a table called fooo with the two columns: create table fooo ( cola varchar(5), colb time ); Inserting some records: insert into fooo values ('a','10:00:00'), ('a','10:30:00'), ('b','20:00:00'), ('c','13:00:00') , ('d','01:00:00'), ('e','10:10:00'), ('f','02:01:00'), ('g','02:20:00') , ('h','04:00:00'), ('i','05:00:00'), ('j','06:00:00'), ('k','07:00:00') , ('l','08:00:00'), ('m','09:00:00'), ('n','22:00:00'), ('o','23:00:00'); And the expected output should be looks like the following format: Expected output: cola 01 02 03 04