postgresql

Removing COMMENT ON from all objects in PostgreSQL

大兔子大兔子 提交于 2021-02-20 16:19:11
问题 In the same vein as pg_dump without comments on objects?, is anyone aware of a command to quickly get rid of the comments (created with COMMENT ON ) on all objects at once ? For now, I resorted to bash generating a SQL script that would void one by one the comments on each table/view/column, but it is quite slow, especially with >4000 columns. Example: COMMENT ON COLUMN table1.column1 IS NULL; COMMENT ON COLUMN table1.column2 IS NULL; COMMENT ON COLUMN table1.column3 IS NULL; ... 回答1: I have

How can I verify in Postgresql that JSON is valid?

拥有回忆 提交于 2021-02-20 06:20:15
问题 I've got a big database with analytics data written in JSON. I want to filter out rows with incorrect data: invalid json (some rows has something like that: '{"hello": "world' some attributes is not array so it would take '{"products": [1,2,3]}' and will leave out the '{"products": 1}' I want to do something like that: select * from analytics where (is_correct_json(json::json)) and (is_array(json::json->>'products')) How can I achieve that? 回答1: This is another good example why choosing the

How can I verify in Postgresql that JSON is valid?

我是研究僧i 提交于 2021-02-20 06:18:20
问题 I've got a big database with analytics data written in JSON. I want to filter out rows with incorrect data: invalid json (some rows has something like that: '{"hello": "world' some attributes is not array so it would take '{"products": [1,2,3]}' and will leave out the '{"products": 1}' I want to do something like that: select * from analytics where (is_correct_json(json::json)) and (is_array(json::json->>'products')) How can I achieve that? 回答1: This is another good example why choosing the

How can I verify in Postgresql that JSON is valid?

自作多情 提交于 2021-02-20 06:17:02
问题 I've got a big database with analytics data written in JSON. I want to filter out rows with incorrect data: invalid json (some rows has something like that: '{"hello": "world' some attributes is not array so it would take '{"products": [1,2,3]}' and will leave out the '{"products": 1}' I want to do something like that: select * from analytics where (is_correct_json(json::json)) and (is_array(json::json->>'products')) How can I achieve that? 回答1: This is another good example why choosing the

How can I verify in Postgresql that JSON is valid?

橙三吉。 提交于 2021-02-20 06:16:58
问题 I've got a big database with analytics data written in JSON. I want to filter out rows with incorrect data: invalid json (some rows has something like that: '{"hello": "world' some attributes is not array so it would take '{"products": [1,2,3]}' and will leave out the '{"products": 1}' I want to do something like that: select * from analytics where (is_correct_json(json::json)) and (is_array(json::json->>'products')) How can I achieve that? 回答1: This is another good example why choosing the

sqlmap使用

霸气de小男生 提交于 2021-02-20 04:54:23
SQLmap是一种开源渗透测试工具,可自动执行SQL注入缺陷的检测和开发过程,并接管数据库服务器。它有强大的检测引擎,针对不同类型的数据库提供多样的渗透测试功能选项,实现数据库识别、数据获取、访问DBMS\操作系统甚至通过带外数据连接的方式执行操作系统的命令。以及从数据库指纹识别、从数据库获取数据、访问底层文件的广泛范围的交换机通过带外连接在操作系统上执行命令。 SQLMAP支持的数据包括:MySQL, Oracle,PostgreSQL,Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird,Sybase和SAP MaxDB等数据库。 Sqlmap使用经验总结 1 在使用-v参数的时候,尽量选择,3级别,次级别可以显示注入的参数。 例如:sqlmap -v3 -u www.potian.com 2 当一件知道数据库信息的时候,使用-d直接连接数据库,注意-D是指定目标库,要区分。 例如:-d mysql://POTIAN : 123123 @127.0.0.1:3306/ ORDER 3 当使用Burp或WebScarab保存了日志的时候,想从日志文件中筛选目标,可使用-I使用 绝对路径地址即可。 4 -g可以使用google的搜索结果,例如,直接搜索uid=,查找具有此参数的站点

Yii2: how to specify multiples database schemas?

走远了吗. 提交于 2021-02-20 04:51:10
问题 I am using PostgreSQL and the default database schema in my Yii2 application. I created a new schema called laboratory and I need to define it in the common/config/main-local.php file. This is my current main-local.php file: <?php return [ 'components' => [ 'db' => [ 'class' => 'yii\db\Connection', 'dsn' => 'pgsql:host=localhost;dbname=travel', 'username' => 'aaaa', 'password' => 'bbbb', 'charset' => 'utf8', ], ], ]; How can I add the laboratory schema in this file? I need both schemas. Is

Get the string of the query that fired a trigger

安稳与你 提交于 2021-02-20 04:26:07
问题 I am creating a control table in a PostgreSQL database, this table should register the query that fired a trigger in a specific table. For instance if I do insert into employees('bob'); I would like to be able to capture the string 'insert into employees('bob');' inside a trigger associated with employees table. It doesn't matter if the trigger is before or after. 回答1: Use the function current_query() in the trigger function. insert into control_table(query_text) select current_query(); The

issue with encoding when importing json into Postgres

廉价感情. 提交于 2021-02-20 04:09:50
问题 I'm using pandas, and exporting data as json like this: import pandas as pd df = pd.DataFrame({'a': ['Têst']}) df.to_json(orient='records', lines=True) > u'{"a":"T\\u00east"}' This makes sense since we have a Unicode character 00ea prefixed with \u and it is escaped with \ when converted to JSON But then I import the JSON strings into Postgres with COPY buffer = cStringIO.StringIO() buffer.write(df.to_json(orient='records', lines=True)) buffer.seek(0) with connection.cursor() as cursor:

Postgresql slow delete from where exists

我只是一个虾纸丫 提交于 2021-02-20 04:06:39
问题 I'm having trouble with slow delete queries. I have a schema ,say "target" containing tables that all have an equivalent table (identical columns & primary keys) in another one, say "delta". I now want to delete all rows that appear in the delta schema from the target schema. I have tried this using the DELETE FROM WHERE EXISTS approach, but that seems incredibly slow. Here's an example query: DELETE FROM "target".name2phoneme WHERE EXISTS( SELECT 1 FROM delta.name2phoneme d WHERE