postgresql-9.5

CSV copy to Postgres with array of custom type using JDBC

懵懂的女人 提交于 2020-08-26 15:27:09
问题 I have a custom type defined in my database as CREATE TYPE address AS (ip inet, port int); And a table that uses this type in an array: CREATE TABLE my_table ( addresses address[] NULL ) I have a sample CSV file with the following contents {(10.10.10.1,80),(10.10.10.2,443)} {(10.10.10.3,8080),(10.10.10.4,4040)} And I use the following code snippet to perform my COPY: Class.forName("org.postgresql.Driver"); String input = loadCsvFromFile(); Reader reader = new StringReader(input); Connection

Setting a customized option in a stored procedure

夙愿已清 提交于 2020-07-22 22:26:14
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

Setting a customized option in a stored procedure

最后都变了- 提交于 2020-07-22 22:21:54
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution

Setting a customized option in a stored procedure

ⅰ亾dé卋堺 提交于 2020-07-22 22:19:16
问题 I'm trying to set a custom option in a stored procedure, but it is storing the variable name and not contents of the variable. CREATE OR REPLACE FUNCTION set_user(_user_id bigint, is_local boolean default true) returns void AS $$ BEGIN SET my.user_id TO _user_id; END; $$ LANGUAGE PLPGSQL; select set_user(1); select current_setting('my.user_id'); current_setting ----------------- _user_id (1 row) I expect current_setting to return 1 , not the string value "_user_id" . 回答1: First solution