小编Dav*_*han的帖子

UPDATE FROM子句中的GROUP BY

我真的需要这样做:

UPDATE table t1 
SET column1=t2.column1 
FROM table t2 
INNER JOIN table t3 
USING (column2) 
GROUP BY t1.column2;
Run Code Online (Sandbox Code Playgroud)

但postgres说我有关于GROUP BY子句的语法错误.有什么不同的方法呢?

postgresql group-by

24
推荐指数
1
解决办法
4万
查看次数

计算tic tac toe唯一状态的有效算法

我正在尝试构建一个tic tac toe游戏来演示和试验机器学习算法,我发现了一个有趣的问题.

例如:一个tic tac toe board可以被镜像,但是对于机器学习目的,这两种状态都是等效的

x _ o     o _ x
o o x  =  x o o
_ _ _     _ _ _
Run Code Online (Sandbox Code Playgroud)

同样的轮换

x _ o   _ _ x   _ _ _   o _ _
_ _ _ = _ _ _ = _ _ _ = _ _ _ 
_ _ _   _ _ o   o _ x   x _ _
Run Code Online (Sandbox Code Playgroud)

最后,并列

x _ o   o _ x
_ x _ …
Run Code Online (Sandbox Code Playgroud)

algorithm math rotation

14
推荐指数
1
解决办法
2893
查看次数

postgresql中的双外键

我试图使用双主键作为外键.

Create table AAA (
   AAA_id int primary key
);

create table BBB (
   AAA_id int,
   BBB_name character varying(20),
   primary key (AAA_id, BBB_name)
);

create table CCC (
    AAA_id,
    BBB_name,
    DDD_id,

    ... ???
);
Run Code Online (Sandbox Code Playgroud)

表AAA是一个对象

表BBB与AAA有多对一,并且拥有AAA的别名

我正在尝试创建一个数据透视表,CCC在DDD和BBB之间保持多对一.

我想我想要类似的东西

create table CCC (
    AAA_id,
    BBB_name,
    DDD_id,
    foreign key (AAA_id, BBB_name) references BBB(AAA_id, BBB_name) on update cascade
);
Run Code Online (Sandbox Code Playgroud)

其中AAA_id和BBB_name都是外键,但它们也始终引用BBB中的同一行.

但当然这是无效的.在postgreSQL中产生这种行为的最佳方法是什么?

sql postgresql database-design foreign-keys

14
推荐指数
1
解决办法
1万
查看次数

在构建期间是否可以将环境变量传递给Ember cli sass?

我正在使用ember-cli-sass

我想根据env变量定义一些sass变量.

我的theme1.scss文件

@if 'theme1' == process.env.THEME {
  $color-secondary: #eee;
  $color-primary: #ff0;
}
Run Code Online (Sandbox Code Playgroud)

我如何将我的env发送到西兰花构建过程

以及如何在sass脚本中访问env变量?

sass ember.js ember-cli broccolijs

8
推荐指数
1
解决办法
955
查看次数

如何在drupal 7中使用自定义数据类型作为字段?

我在drupal 7中有几个自定义数据类型

  1. 餐厅
  2. 菜单
  3. 食谱
  4. 厨师

我想在这个数据厨师 - >餐厅 - >菜单 - >食谱之间创建关联,这样食谱可以获得厨师的名字,餐馆的地址和菜单可以获得食谱清单等

在SQL领域,我称之为外键,但我在drupal 7中发现如何做到这一点有很多问题.

我怀疑必须有一些我不熟悉的模块或功能.但drupal使用它自己的术语,我认为我正在贬低我的google-fu

有谁知道我在找什么?

drupal drupal-7

5
推荐指数
1
解决办法
1196
查看次数

在大型Unicode代码点上进行Perl正则表达式匹配

我试图用单引号或双引号替换各种字符.

这是我的测试文件:

# Replace all with double quotes
? fullwidth
“ left
” right
„ low
" normal

# Replace all with single quotes
' normal
‘ left
’ right
‚ low
? reverse
` backtick
Run Code Online (Sandbox Code Playgroud)

我正试图这样做......

perl -Mutf8 -pi -e "s/[\x{2018}\x{201A}\x{201B}\x{FF07}\x{2019}\x{60}]/'/ug" test.txt
perl -Mutf8 -pi -e 's/[\x{FF02}\x{201C}\x{201D}\x{201E}]/"/ug' text.txt
Run Code Online (Sandbox Code Playgroud)

但只有反引号字符才能被正确替换.我认为它与其他代码点太大有关,但我找不到任何关于此的文档.

在这里,我有一个单行代码转储Unicode代码点,以验证它们是否与我的正则表达式匹配.

$ awk -F\  '{print $1}' test.txt | \
    perl -C7 -ne 'for(split(//)){print sprintf("U+%04X", ord)." ".$_."\n"}'

U+FF02 ?
U+201C “
U+201D ”
U+201E „
U+0022 "

U+0027 ' …
Run Code Online (Sandbox Code Playgroud)

regex unicode perl encoding

5
推荐指数
2
解决办法
5930
查看次数

基于索引名称而不是表(列)创建外键

我有一个带有时间戳字段的表,我在其上创建了一个复合索引.

CREATE INDEX "IDX_NAME_A" ON TABLE "A" (a_id, extract(year FROM created_at))
Run Code Online (Sandbox Code Playgroud)

我有另一个表存储一年和a_id我希望有一个外键关系.

我似乎无法找到做我想要的语法.

ALTER TABLE "B" 
  ADD FOREIGN KEY(a_id, a_year) 
  REFERENCES A(a_id, extract(YEAR FROM created_at));
Run Code Online (Sandbox Code Playgroud)

生产:

ERROR:  syntax error at or near "("
Run Code Online (Sandbox Code Playgroud)

我也试过......

ALTER TABLE "B"
  ADD FOREIGN KEY(a_id, a_year) 
  USING INDEX "IDX_NAME_A";
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Table A
--------
a_id serial,
created_at timestamp default now()

Table B
-------
b_id serial
a_id integer not null,
a_year date_part('year')
Run Code Online (Sandbox Code Playgroud)

sql postgresql indexing foreign-keys

1
推荐指数
1
解决办法
222
查看次数