postgresql-9.3

LocalDateTime to ZonedDateTime

好久不见. 提交于 2019-12-03 04:14:19
问题 I have Java 8 Spring web app that will support multiple regions. I need to make calendar events for a customer location. So lets say my web and Postgres server is hosted in MST timezone (but I guess it could be anywhere if we go cloud). But the customer is in EST. So, following some best practices I read, I thought I would store all date times in UTC format. All date time fields in the database are declared as TIMESTAMP. So here is how I take a LocalDateTime and convert to UTC: ZonedDateTime

How to refresh all materialized views in Postgresql 9.3 at once?

亡梦爱人 提交于 2019-12-03 01:46:25
I am loading a bunch of data into a PostgresQL 9.3 database and then I want to refresh all materialized views that depend on the updated tables. Is there a way to do it automatically instead of going through each view and refreshing them one by one? I know that Oracle can do that rather easily but I did not find anything after combing through PostgreSQL documentation. Looks like current version of PostgreSQL (9.3.1) does not have such functionality, have had to write my own function instead: CREATE OR REPLACE FUNCTION RefreshAllMaterializedViews(schema_arg TEXT DEFAULT 'public') RETURNS INT AS

Pass UUID value as a parameter to the function

僤鯓⒐⒋嵵緔 提交于 2019-12-02 15:40:37
问题 I have the table with some columns: --table create table testz ( ID uuid, name text ); Note : I want to insert ID values by passing as a parameter to the function. Because I am generating the ID value in the front end by using uuid_generate_v4() . So I need to pass the generated value to the function to insert into the table My bad try: --function CREATE OR REPLACE FUNCTION testz ( p_id varchar(50), p_name text ) RETURNS VOID AS $BODY$ BEGIN INSERT INTO testz values(p_id,p_name); END; $BODY$

How to create columns for different fields without applying the pivoting function

≡放荡痞女 提交于 2019-12-02 12:02:35
So i have a question for the tough hearted! I have had an issue with this concept for awhile and I need it to be cleared... The following code shows students who have more than 1 language SELECT DISTINCT s.studentnumber as studentnr, p.firstname AS name, sl.gradenumber as gradenumber, string_agg(DISTINCT l.text, ', ') as languages FROM student s JOIN pupil p ON p.id = s.pupilid JOIN pupillanguage pl on pl.pupilid = p.id JOIN language l on l.id = pl.languageid JOIN schoollevel sl ON sl.id = p.schoollevelid GROUP BY s.studentnumber, p.firstname Result Now my question is simple yet I'm not sure

Part 2: how to get the Sum of a partition based query without actually pivoting

你离开我真会死。 提交于 2019-12-02 10:32:03
问题 so since I dont have the latest version of Postgresql (I have Postgresql 9.3) its been impossible for me to come up with a function similar to the pivot function that calculates the total value of a particalar field. You can click the link below to use a question I created as reference, they are similar in code but different in the aspect of requirements but there is a second query that uses array and also produces the exact same results. How to create columns for different fields without

Passing the table as a parameter

萝らか妹 提交于 2019-12-02 10:05:47
I have to convert from lat and long to geom to use PostGIS. My problem, I have various tables from different locations and I want to pass the table as a parameter to the function. I'm trying this: CREATE or REPLACE FUNCTION convert_from_lon_lat(float,float,character varying) RETURNS integer AS $$ select id from $3 as vertices order by vertices.geom <-> ST_SetSrid(ST_MakePoint($1,$2),4326) LIMIT 1; $$ LANGUAGE SQL; but I get a syntax error. EDIT1: So I changed the previous code to this: CREATE or REPLACE FUNCTION convert_from_lon_lat(long float, lat float, _table character varying) RETURNS

Pass UUID value as a parameter to the function

我是研究僧i 提交于 2019-12-02 08:28:29
I have the table with some columns: --table create table testz ( ID uuid, name text ); Note : I want to insert ID values by passing as a parameter to the function. Because I am generating the ID value in the front end by using uuid_generate_v4() . So I need to pass the generated value to the function to insert into the table My bad try: --function CREATE OR REPLACE FUNCTION testz ( p_id varchar(50), p_name text ) RETURNS VOID AS $BODY$ BEGIN INSERT INTO testz values(p_id,p_name); END; $BODY$ LANGUAGE PLPGSQL; --EXECUTE FUNCTION SELECT testz('24f9aa53-e15c-4813-8ec3-ede1495e05f1','Abc');

Implement search filter for all columns

柔情痞子 提交于 2019-12-02 07:31:38
I found this search example in PostgreSQL http://www.postgresql.org/docs/current/interactive/textsearch-tables.html#TEXTSEARCH-TABLES-SEARCH I tried to implement this code for this table this way: CREATE TABLE ACCOUNT( ID INTEGER NOT NULL, USER_NAME TEXT, PASSWD TEXT, FIRST_NAME TEXT, LAST_NAME TEXT, LAST_LOGIN DATE, DATE_REGISTERED DATE, ROLE INTEGER, CAN_LOGIN INTEGER ) ; -- ADD KEYS FOR TABLE ACCOUNT ALTER TABLE ACCOUNT ADD CONSTRAINT KEY1 PRIMARY KEY (ID) ; Java code public List<AccountsObj> list(int firstRow, int rowCount, String sortField, boolean sortAscending) throws SQLException {

Part 2: how to get the Sum of a partition based query without actually pivoting

若如初见. 提交于 2019-12-02 06:19:00
so since I dont have the latest version of Postgresql (I have Postgresql 9.3) its been impossible for me to come up with a function similar to the pivot function that calculates the total value of a particalar field. You can click the link below to use a question I created as reference, they are similar in code but different in the aspect of requirements but there is a second query that uses array and also produces the exact same results. How to create columns for different fields without applying the pivoting function I currently get the following results I want these results Below I have a

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

无人久伴 提交于 2019-12-02 04:59:08
问题 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: