postgresql-9.6

Syntax error at or near $1 while trying to alter type in postgreSQL-9.6

£可爱£侵袭症+ 提交于 2021-02-20 03:46:39
问题 I'm trying to add a value to an enumerated type in postgreSQL-9.6, and am having trouble figuring out what I'm doing wrong. var tc = new NpgsqlCommand(@"ALTER TYPE attributeName ADD VALUE IF NOT EXISTS :a", conn); //tc.Parameters.Add(new NpgsqlParameter("a", NpgsqlDbType.Text)); //tc.Parameters[0].Value = "test"; tc.Parameters.AddWithValue("a", NpgsqlDbType.Text, "test"); tc.ExecuteNonQuery(); I tried both the commented out code and the current version, and both resulted in an exception. The

Spring Batch and Postgres database slow write

柔情痞子 提交于 2021-02-19 08:22:07
问题 I've developed a Spring Batch App with the Postgres and particularly facing slow write to database issue for 3 Steps out of 20 steps. I'd like to share example which is taking most time among three. Below is the table where I'm writing data and data count is 2,33,382 . I'm using Spring JDBC and in particular NamedParameterJdbcTemplate to perform the Batch update. CREATE TABLE test.country ( last_update_date date NULL, src_system varchar(20) NULL, country_id varchar(255) NULL, app_id varchar

Optimizing a postgres similarity query (pg_trgm + gin index)

喜夏-厌秋 提交于 2021-02-17 22:52:16
问题 I have defined the following index: CREATE INDEX users_search_idx ON auth_user USING gin( username gin_trgm_ops, first_name gin_trgm_ops, last_name gin_trgm_ops ); I am performing the following query: PREPARE user_search (TEXT, INT) AS SELECT username, email, first_name, last_name, ( -- would probably do per-field weightings here s_username + s_first_name + s_last_name ) rank FROM auth_user, similarity(username, $1) s_username, similarity(first_name, $1) s_first_name, similarity(last_name, $1

How can I fix the error with json_object in postgresql-9.6?

爷,独闯天下 提交于 2021-02-11 14:21:40
问题 There is Zabbix with PostgreSQL database monitoring. There is one trigger in Zabbix that constantly spam error: ERROR: function json_object(text[], text[]) does not exist LINE 11: SELECT json_object(array_agg(name), array_agg(setting)) F... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 190 Found a template in which this trigger is registered. It is standard, I tried to request a line separately in Postgres

Getting PSQLException while calling a Stored Procedure (which inserts record into lsa_user_info table) from Java method ( which is in DAO Layer)

回眸只為那壹抹淺笑 提交于 2021-02-11 13:46:57
问题 I am new to stored procedures. I want to insert a record with 20 column values into lsa_user_info table. I am invoking a stored procedure to do this task. Also, I'm expecting the resultset will return the primary key value of the record that was inserted ( user_id ). But, I'm getting this error instead: org.postgresql.util.PSQLException: **The column index is out of range: 20, number of columns: 19. lsa_user_info table definition : CREATE TABLE public.lsa_user_info ( user_id integer NOT NULL

Filter rows based on values inside multiple JSONB columns

…衆ロ難τιáo~ 提交于 2021-02-10 15:49:36
问题 I am trying to search a table in a LIKE %str% fashion but on fields inside json values over multiple columns . I have a table which has three jsonb columns change , previous and specific_changes . As you might imagine the content is JSON but the structure of that json is not know ahead of time, therefor i can't use the -> or ->> in query like so: select * from change_log where change -> 'field' = '"something"' create table change_log ( id serial not null constraint pk_change_log primary key,

Why are the result of COUNT double when I do two join? [duplicate]

巧了我就是萌 提交于 2021-01-27 06:07:23
问题 This question already has answers here : sql double count in join statement (2 answers) Closed 3 years ago . I have this tables device id name groupId serviceId 791 Mamie Ortega 205 1832 group id serviceId 205 1832 record id date deviceId 792 2017-07-13 13:30:19.740360 784 793 2017-07-13 13:30:19.742799 784 alarms id status deviceId 241 new 784 242 new 784 I'm running this query SELECT device.id, device.name, COUNT(records.id) AS "last24HMessagesCount", COUNT(alarms.id) AS "activeAlarmsCount"

Why are the result of COUNT double when I do two join? [duplicate]

孤街浪徒 提交于 2021-01-27 06:07:13
问题 This question already has answers here : sql double count in join statement (2 answers) Closed 3 years ago . I have this tables device id name groupId serviceId 791 Mamie Ortega 205 1832 group id serviceId 205 1832 record id date deviceId 792 2017-07-13 13:30:19.740360 784 793 2017-07-13 13:30:19.742799 784 alarms id status deviceId 241 new 784 242 new 784 I'm running this query SELECT device.id, device.name, COUNT(records.id) AS "last24HMessagesCount", COUNT(alarms.id) AS "activeAlarmsCount"

Querying Postgres 9.6 JSONB array of objects

丶灬走出姿态 提交于 2020-12-29 10:16:52
问题 I have the following table: CREATE TABLE trip ( id SERIAL PRIMARY KEY , gps_data_json jsonb NOT NULL ); The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below): mode timestamp latitude longitude I'm trying to get all rows that contain a certain "mode". SELECT * FROM trip where gps_data_json ->> 'mode' = 'WALK'; I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?

Querying Postgres 9.6 JSONB array of objects

ぃ、小莉子 提交于 2020-12-29 10:15:13
问题 I have the following table: CREATE TABLE trip ( id SERIAL PRIMARY KEY , gps_data_json jsonb NOT NULL ); The JSON in gps_data_json contains an array of of trip objects with the following fields (sample data below): mode timestamp latitude longitude I'm trying to get all rows that contain a certain "mode". SELECT * FROM trip where gps_data_json ->> 'mode' = 'WALK'; I pretty sure I'm using the ->> operator wrong, but I'm unsure who to tell the query that the JSONB field is an array of objects?