postgresql

Table as an argument of a PostgreSQL function

廉价感情. 提交于 2021-02-13 17:33:59
问题 I'm trying to pass a table as an argument in a PostgreSQL function, and I can't find the right keyword (what should be instead of table in my code) in the first line : CREATE FUNCTION test.fcttest(table) RETURNS SETOF test.out_table AS $$ INSERT INTO test.out_table /* obviously, the schema for this table is what it should be, an int column for A.id and a varchar(30) column for A.another_field */ SELECT A.id, A.another_field FROM $1 A; SELECT A.id, A.another_field FROM $1 A; $$ LANGUAGE SQL;

Why do SQL id sequences go out of sync (specifically using Postgres)?

≡放荡痞女 提交于 2021-02-13 12:04:03
问题 I've seen solutions for updating a sequence when it goes out of sync with the primary key it's generating, but I don't understand how this problem occurs in the first place. Does anyone have insight into how a primary key field, with its default defined as the nextval of a sequence, whose primary keys aren't set explicitly anywhere, can go out of sync with the sequence? I'm using Postgres, and we see this occur now and then. It results eventually in a duplicate key constraint when the

Why do SQL id sequences go out of sync (specifically using Postgres)?

强颜欢笑 提交于 2021-02-13 12:02:57
问题 I've seen solutions for updating a sequence when it goes out of sync with the primary key it's generating, but I don't understand how this problem occurs in the first place. Does anyone have insight into how a primary key field, with its default defined as the nextval of a sequence, whose primary keys aren't set explicitly anywhere, can go out of sync with the sequence? I'm using Postgres, and we see this occur now and then. It results eventually in a duplicate key constraint when the

Why do SQL id sequences go out of sync (specifically using Postgres)?

时间秒杀一切 提交于 2021-02-13 12:02:15
问题 I've seen solutions for updating a sequence when it goes out of sync with the primary key it's generating, but I don't understand how this problem occurs in the first place. Does anyone have insight into how a primary key field, with its default defined as the nextval of a sequence, whose primary keys aren't set explicitly anywhere, can go out of sync with the sequence? I'm using Postgres, and we see this occur now and then. It results eventually in a duplicate key constraint when the

简单介绍基于PostgreSql 别名区分大小写的问题

a 夏天 提交于 2021-02-13 09:48:24
这篇文章主要介绍了基于PostgreSql 别名区分大小写的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧 PostgreSql是区分大小写的 如果别名的大小不一致就会提示错误: SELECT * FROM ( SELECT cpi."product_item_id" "PRODUCT_ITEM_ID" FROM prd.up_product_item cpi ) a WHERE a.PRODUCT_ITEM_ID=1 一个很简单的子查询,但是会出错,虽然从语句上看大小写是一致的,但是内部查询中还是使用了小写。PostgreSql对于大写都需要加上双引号的,不然还是视作小写而定。 正确的写法如下 SELECT * FROM ( SELECT cpi."product_item_id" "PRODUCT_ITEM_ID" FROM prd.up_product_item cpi ) a WHERE a."PRODUCT_ITEM_ID"=1 补充:postgresql查询字段别名大写的要加双引号 PostgreSQL对表名、字段名都是区分大小写的。在图形化界面可以正常新建。用SQL语句的时候需要加双引号,如果jdbc查询等处,记得使用转义符号。PostgreSQL在SQL语句中对大小写是不敏感的。select ID from t_user 和 select id

Error: Column does not exist in postgresql for update [duplicate]

假装没事ソ 提交于 2021-02-13 05:48:27
问题 This question already has answers here : Postgres error updating column data (2 answers) PostgreSQL “column ”foo“ does not exist” where foo is the value (1 answer) postgres column “X” does not exist (1 answer) Simple Postgresql Statement - column name does not exists (2 answers) Closed 10 months ago . I am trying to insert a line of text into a column where that column is null. Error listed below. Any help is greatly appreciated UPDATE public.meditech_ar_test4 SET filename = "text" WHERE

Error: Column does not exist in postgresql for update [duplicate]

房东的猫 提交于 2021-02-13 05:45:39
问题 This question already has answers here : Postgres error updating column data (2 answers) PostgreSQL “column ”foo“ does not exist” where foo is the value (1 answer) postgres column “X” does not exist (1 answer) Simple Postgresql Statement - column name does not exists (2 answers) Closed 10 months ago . I am trying to insert a line of text into a column where that column is null. Error listed below. Any help is greatly appreciated UPDATE public.meditech_ar_test4 SET filename = "text" WHERE

【Django】ORM操作#2

本小妞迷上赌 提交于 2021-02-13 05:26:04
@[TOC] 必知必会的13条查询方法 ==1. all()== 查询所有结果 . **==2. get( kwargs)== 返回与所给筛选条件相匹配的对象,返回结果有且只有一个. 如果符合筛选条件的对象超过一个或者没有,都将抛出异常. . **==3. filter( kwargs)== 返回所有符合筛选条件的对象. . **==4. exclude( kwargs)== 返回所有不符合筛选条件的对象 . * ==5. values( field)== 返回一个ValueQuerySet(一个特殊的QuerySet). 运行后得到的并不是一系列model的实例化对象,而是一个可迭代的字典序列. 例如(返回值): <QuerySet [{'id': 1, 'name': 'zyk', 'age': 24, 'birth': datetime.datetime(2018, 10, 11, 1, 17, 47, 380591, tzinfo=<UTC>), 'phone': '17600390376'}]> . * ==6. values_list( field)== 它与values()非常类似,它返回的是一个元组序列,values返回的是一字典序列 . * ==7. order_by( field)== 对查询结果排序. 参数接收字符串类型的字段,指定按某个字段排序. 使用负号

PostgreSql 备份之 pg_probackup

假如想象 提交于 2021-02-12 08:42:22
PostgreSql 备份的软件(免费)的有不少,pgrman(之前有一篇写过), Barman (功能很强大,配置很复杂)。最近大佬微信公众号发布 pg_probackup 功能和ORACLE rman 相差无几。 下面我们就来看看pg_probackup 何许人也。 pg_probackup是一款免费的postgresql 备份软件,目前支持到 postgresql 11 , 这是一名 RU 的 DEV 开发者开发的备份工具。作为postgresql 使用流行的国家,相关的软件也不少(日本,俄罗斯)。 这个小哥哥的其他产品也是很有名,例如 pg_pathman 安装很简单,安装了小哥哥的 repo rpm -ivh http://repo.postgrespro.ru/pg_probackup/keys/pg_probackup-repo-centos.noarch.rpm yum install pg_probackup-{11,10,9.6,9.5} 那这个备份软件到底对比其他的备份有什么优势 1 可以选择全备和增量备份方式,加速大库的备份速度 2 自动数据一致性检查和按需备份验证,无需实际的数据恢复 3 在多个并行线程上运行备份、恢复和验证进程 4 以压缩状态存储备份数据以节省磁盘空间 5 从备用服务器进行备份以避免主服务器上的额外负载 6 简化WAL日志归档的自定义命令

为什么有些大公司技术弱爆了?

血红的双手。 提交于 2021-02-11 21:18:26
这是我个人觉得蛮有意思的一篇文章,不是说里面的问题,而是两方暴露出来的问题现象,我们常说的业务价值和技术价值的权衡,其实精髓就在此,当然里面有些言论有些激烈,很多牢骚抱怨我们也有过,换个角度来想,也就释然了。这篇文章我看了很多遍,我喜欢看那些深刻的问题而不是个别敏感的字眼。所以推荐大家阅读也吸取有价值的思想,不要太拘泥于里面的个别表达方式。问题讨论的知乎链接为: https://www.zhihu.com/question/32039226/ ----------------------------------------------------------- 今年年初,到一家互联网公司实习,该公司是国内行业龙头。 不过技术和管理方面,却弱爆了。 那里的程序员,每天都在看邮件,查问题工单。 这些问题,多半是他们设计不当,造成的。 代码写的一团糟,全是复制粘贴,连作者都没改,大家普遍不写注释,也不格式化,代码歪歪扭扭。 一个项目里,httpclient竟然出现了四种。 一种是该公司研发部写的, 一种是老版本的开源项目, 一种是新版本的开源项目, 还有一种是开发人员造的轮子。 打接口请求响应日志,竟然不知道用拦截器。 打错误日志竟然不打上下文信息,每个人一种日志风格,千奇百怪。 许多重要的中间流程,居然不打日志。 idea、eclipse