postgresql

Switch from JsonStringType to JsonBinaryType when the project uses both MySQL and PostgreSQL

青春壹個敷衍的年華 提交于 2021-02-09 08:26:09
问题 I have a problem with column json when it's necessary to switching from PostgreSQL to MariaDB/MySql. I use Spring Boot + JPA + Hibernate + hibernate-types-52. The table i want to map is like this: CREATE TABLE atable( ... acolumn JSON, ... ); Ok it works for PostgreSQL and MariaDB/MySql. The problem is when i want to deploy an application that switch easly from one to another because the correct hibernate-types-52 implementation for PostgreSQL and MySQL/MariaDB are different This works on

Execute a Bash script (Shell Script) from postgres function/procedure/trigger

*爱你&永不变心* 提交于 2021-02-09 08:11:00
问题 CREATE or replace FUNCTION test() RETURNS boolean AS $$ $filename = '/home/postgres'; if (-e $filename) { exec /home/postgres/test.sh & return true; } return false; $$ LANGUAGE plperlu; exec /home/postgres/test.sh & its showing syntax error. Could you please help how to call bash script into postgres funtion/procedure 回答1: Presumably, the code needs to be syntactically valid Perl. So you'll need to clean up a few bits. CREATE or replace FUNCTION test() RETURNS boolean AS $$ my $filename = '

Execute a Bash script (Shell Script) from postgres function/procedure/trigger

送分小仙女□ 提交于 2021-02-09 08:08:13
问题 CREATE or replace FUNCTION test() RETURNS boolean AS $$ $filename = '/home/postgres'; if (-e $filename) { exec /home/postgres/test.sh & return true; } return false; $$ LANGUAGE plperlu; exec /home/postgres/test.sh & its showing syntax error. Could you please help how to call bash script into postgres funtion/procedure 回答1: Presumably, the code needs to be syntactically valid Perl. So you'll need to clean up a few bits. CREATE or replace FUNCTION test() RETURNS boolean AS $$ my $filename = '

Execute a Bash script (Shell Script) from postgres function/procedure/trigger

半腔热情 提交于 2021-02-09 08:06:59
问题 CREATE or replace FUNCTION test() RETURNS boolean AS $$ $filename = '/home/postgres'; if (-e $filename) { exec /home/postgres/test.sh & return true; } return false; $$ LANGUAGE plperlu; exec /home/postgres/test.sh & its showing syntax error. Could you please help how to call bash script into postgres funtion/procedure 回答1: Presumably, the code needs to be syntactically valid Perl. So you'll need to clean up a few bits. CREATE or replace FUNCTION test() RETURNS boolean AS $$ my $filename = '

Python psycopg2 cursor.fetchall() returns empty list but cursor.rowcount is > 1

早过忘川 提交于 2021-02-09 07:20:51
问题 I am getting an issue here: conn = psycopg2.connect(conn_string) cursor = conn.cursor() sql = """ SELECT DISTINCT (tenor_years) FROM bond_pnl WHERE country = '%s' """ % country cursor.execute(sql) print(cursor.fetchall()) print(cursor.rowcount) It gives the following output: [] 11 which means that cursor.rowcount is 11 but cursor.fetchall() is empty list. I have already tried doing this: conn.set_session(readonly=True, autocommit=True) and this solution as well :Click to see Any help

Python psycopg2 cursor.fetchall() returns empty list but cursor.rowcount is > 1

蹲街弑〆低调 提交于 2021-02-09 07:19:25
问题 I am getting an issue here: conn = psycopg2.connect(conn_string) cursor = conn.cursor() sql = """ SELECT DISTINCT (tenor_years) FROM bond_pnl WHERE country = '%s' """ % country cursor.execute(sql) print(cursor.fetchall()) print(cursor.rowcount) It gives the following output: [] 11 which means that cursor.rowcount is 11 but cursor.fetchall() is empty list. I have already tried doing this: conn.set_session(readonly=True, autocommit=True) and this solution as well :Click to see Any help

Get created table name

不打扰是莪最后的温柔 提交于 2021-02-09 04:26:59
问题 I'm trying to create a event trigger , executed whenever a table is created . When this happens I would like to insert into a table ( which has 2 columns id and tablename ) the name of the table created. Reading the docs I'm not able to find how can i get the table name. So far I have this: CREATE OR REPLACE FUNCTION insert_layer() RETURNS event_trigger AS $$ DECLARE r RECORD; BEGIN RAISE NOTICE 'event for % ', tg_tag; -- I would like to execute this --EXECUTE format('INSERT INTO "public

Get created table name

强颜欢笑 提交于 2021-02-09 04:23:11
问题 I'm trying to create a event trigger , executed whenever a table is created . When this happens I would like to insert into a table ( which has 2 columns id and tablename ) the name of the table created. Reading the docs I'm not able to find how can i get the table name. So far I have this: CREATE OR REPLACE FUNCTION insert_layer() RETURNS event_trigger AS $$ DECLARE r RECORD; BEGIN RAISE NOTICE 'event for % ', tg_tag; -- I would like to execute this --EXECUTE format('INSERT INTO "public

Get created table name

夙愿已清 提交于 2021-02-09 04:23:01
问题 I'm trying to create a event trigger , executed whenever a table is created . When this happens I would like to insert into a table ( which has 2 columns id and tablename ) the name of the table created. Reading the docs I'm not able to find how can i get the table name. So far I have this: CREATE OR REPLACE FUNCTION insert_layer() RETURNS event_trigger AS $$ DECLARE r RECORD; BEGIN RAISE NOTICE 'event for % ', tg_tag; -- I would like to execute this --EXECUTE format('INSERT INTO "public

Get created table name

≡放荡痞女 提交于 2021-02-09 04:18:45
问题 I'm trying to create a event trigger , executed whenever a table is created . When this happens I would like to insert into a table ( which has 2 columns id and tablename ) the name of the table created. Reading the docs I'm not able to find how can i get the table name. So far I have this: CREATE OR REPLACE FUNCTION insert_layer() RETURNS event_trigger AS $$ DECLARE r RECORD; BEGIN RAISE NOTICE 'event for % ', tg_tag; -- I would like to execute this --EXECUTE format('INSERT INTO "public