我有一个非常普通的表,带有另一个表的外键; 例如:
CREATE TABLE table_a (
id serial NOT NULL,
name text,
CONSTRAINT table_a_pkey PRIMARY KEY (id)
);
CREATE TABLE table_b (
id serial NOT NULL,
a_id integer, -- The foreign key
CONSTRAINT table_b_pkey PRIMARY KEY (id),
CONSTRAINT table_b_a_id_fkey FOREIGN KEY (a_id)
REFERENCES table_a (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
INSERT INTO table_a
VALUES (1, 'First row');
-- 2 entries in table_b which refer to the existing table_a row:
INSERT INTO table_b
VALUES (11, …Run Code Online (Sandbox Code Playgroud) 我有一个基于buildout的Plone站点,具有高效的开发/测试实例.我注意到我目前在构建开发实例时遇到了问题,并且可能与问题相关的差异是在两个实例中"开发"的不同版本的产品.
不幸的是旧版本是有效的...所以我试图将该软件包重置为旧版本并重建:
cd /path/to/my/instance
. bin/activate
cd src/plone.formwidget.recaptcha/
git checkout a0c334406c0d991f4facedce0334ab5566729b2f
cd -
bin/buildout buildout:newest=false
Run Code Online (Sandbox Code Playgroud)
不幸的是,buildout尝试拉动并失败:
mr.developer: git pull of 'plone.formwidget.recaptcha' failed.
mr.developer: You are not currently on a branch. Please specify which
mr.developer: branch you want to merge with. See git-pull(1) for details.
mr.developer:
mr.developer: git pull <remote> <branch>
mr.developer:
mr.developer:
Run Code Online (Sandbox Code Playgroud)
好吧,我不希望git pull发生; 所以我找了mr.developer选项来帮助并添加mr.developer:auto-checkout=到命令行.
还有那个git pull.我怎么能抑制它?那么将软件包固定到所需版本的推荐方法是什么?
我想从代表 URL 的字符串中提取查询参数,并且我想在存储函数中执行此操作(偶然没有我可以使用的标准函数?)。
在 Python 中,这将是:
from urlparse import urlparse, parse_qs
def extract_oid(url):
"""
extract the 'oid' query argument
(simplified, no error handling)
>>> extract_oid('http://some.host/some/path?oid=abc123&other')
'abc123'
"""
return parse_qs(urlparse(url).query)['oid'][0]
Run Code Online (Sandbox Code Playgroud)
我目前的尝试plpgsql是:
CREATE OR REPLACE FUNCTION extract_oid (link text)
RETURNS text
AS $$
DECLARE
pos1 integer := position('&oid=' in link);
tail text := substring(link from pos1 + 1);
endpos integer := position('&' in tail);
BEGIN
if link is NULL or pos1 = 0 then
RETURN NULL;
ELSIF endpos = 0 …Run Code Online (Sandbox Code Playgroud)