作为Postgresql的新手(我正在移动,因为我正在将我的网站移动到只支持它的heroku,我不得不重构我的一些查询和代码.这是一个我无法理解这个问题的问题有:
PGError: ERROR: column "l_user_id" does not exist
LINE 1: ...t_id where l.user_id = 8 order by l2.geopoint_id, l_user_id ...
^
Run Code Online (Sandbox Code Playgroud)
...查询:
select distinct
l2.*,
l.user_id as l_user_id,
l.geopoint_id as l_geopoint_id
from locations l
left join locations l2 on l.geopoint_id = l2.geopoint_id
where l.user_id = 8
order by l2.geopoint_id, l_user_id = l2.user_id desc
Run Code Online (Sandbox Code Playgroud)
添加了"l.user_id为l_user_id,l.geopoint_id为l_geopoint_id"的子句,因为显然postgres不喜欢未选中字段的order子句.但是我现在得到的错误使它看起来像我也没有得到别名.任何有postgres经验的人都会看到问题吗?
我可能会遇到一堆这样的问题 - 查询在mySql中运行良好...
我想实现这样的目标:
SELECT
(CASE WHEN ...) AS FieldA,
FieldA + 20 AS FieldB
FROM Tbl
Run Code Online (Sandbox Code Playgroud)
假设通过"..."我已经替换了一个冗长而复杂的CASE语句,我不想在选择FieldB和使用别名时重复它FieldA.
注意,这将返回多行,因此在我的情况下,语句之外的DECLARE/ 不好.SETSELECT
我希望能够根据列表中包含的对象类型对根列表元素进行别名.例如,这是我当前的输出:
<list>
<coin>Gold</coin>
<coin>Silver</coin>
<coin>Bronze</coin>
</list>
Run Code Online (Sandbox Code Playgroud)
这就是我想要的样子:
<coins>
<coin>Gold</coin>
<coin>Silver</coin>
<coin>Bronze</coin>
</coins>
Run Code Online (Sandbox Code Playgroud)
我可以在全球范围内通过说所有列表应该别名为硬币来做到这一点,但我有很多不同的列表,这是行不通的.关于如何做到这一点的任何想法?看起来它应该很简单,但当然,事实并非如此.
编辑:我应该指定,我正在尝试将对象序列化为xml.我使用Spring 3 MVC作为我的Web框架.
我根据EdgeCase 的Git Immersion教程创建了一个Git别名,如下所示:
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
Run Code Online (Sandbox Code Playgroud)
但现在它似乎正在分页结果 - 显示(END)结果后的终端显示,迫使我Q继续工作.我读到通过添加--no-pager标签,您可以禁用此功能; 如何将其合并到别名中?我在最后,之前log和之后尝试过,而且没有一个能够奏效.Git抛出一个错误,说它是一个无法识别的参数,或者它改变了环境变量.有什么建议?
在Ruby中,当方法有别名时,别名指向原始方法的主体.因此,即使重新定义原始方法,别名也将继续使用原始定义.
class Foo
def bar
"bar"
end
alias :saloon :bar
end
class Foo
def bar
"BAR"
end
end
puts Foo.new.saloon
Run Code Online (Sandbox Code Playgroud)
将返回'bar'而不是'BAR'.有没有办法让轿车使用新的酒吧定义?
编辑:我应该更清楚.这个例子只是一个问题的例子 - 这不是我需要解决的实际问题.当你有链式别名时,问题就更复杂了,例如,在rails的核心中.例如,perform_action由基准测试模块别名,然后由flash模块.所以现在对perform_action的调用实际上是调用perform_action_with_flash执行它的事情,然后有效地调用perform_action_with_benchmarking然后调用原始的perform_action.如果我想覆盖perform_action_with_benchmarking(即使我同意这是一个坏主意 - 请让我们不要讨论它,因为除了这一点),我不能,因为它已被别名,并且据我所知别名指向的是原始perform_action_with_benchmarking的副本,所以即使重新定义它,也没有效果.
我一直在四处寻找将alas clear和ls组合成一个命令的方法.目前我已经定义了命令x:
alias x="clear;ls"
Run Code Online (Sandbox Code Playgroud)
现在是否有任何解决方法以避免递归并定义:
alias ls='clear;ls'
Run Code Online (Sandbox Code Playgroud) 我在~/.bash_aliases远程ubuntu服务器上的文件中有别名.该文件以标准方式从文件加载~/.bashrc,如下所示:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
Run Code Online (Sandbox Code Playgroud)
该~/.bashrc文件依次从~/.profile文件加载(也以标准方式),如下所示:
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
source ~/.bashrc
echo ".profile loaded .bashrc"
fi
fi
mesg n
Run Code Online (Sandbox Code Playgroud)
我发现我的别名在我的结构命令中不可用,例如当我在结构脚本中执行此操作时:
run("aliased_command")
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
run: aliased_command
out: .profile loaded .bashrc
out: /bin/bash: aliased_command: command not found
Fatal error: run() encountered an error (return code 127) while executing 'aliased_command'
Run Code Online (Sandbox Code Playgroud)
现在,我设法通过使用ssh登录到服务器并在运行:
~# /bin/bash -l -c aliased_command
Run Code Online (Sandbox Code Playgroud)
从shell(nb /bin/bash -l -c是结构的默认值,见这里)我得到相同的输出: …
这个问题类似于我的问题: 有没有办法创建一个SQL"别名"?
但是不太一样 - 我正在学习mysql,并且我将使用不同的命令来运行select命令.有没有办法我可以别名的东西:
从testdb中选择*
至
LS
或类似的东西?理想情况下,我可以将"select*from"别名为"show",然后输入"show testdb".
看看将当前用户的别名传递给sudo命令的方法,我在ArchWiki上找到了以下内容:
传递别名
如果您使用了很多别名,您可能已经注意到在使用sudo时它们不会转移到root帐户.但是,有一种简单的方法可以使它们工作.只需将以下内容添加到您
~/.bashrc或/etc/bash.bashrc:
alias sudo='sudo '
我不明白为什么会这样.如果shell不关心两个命令之间有多少空格,这怎么会有效?
手动添加空格时,我认为没有区别:
$ alias e=echo
$ sudo e foo
sudo: e: command not found
$ sudo e foo # Manual space addition
sudo: e: command not found # Fail
$ alias sudo="sudo " # Now with alias
$ sudo e foo
foo # Succeeds, but why?
Run Code Online (Sandbox Code Playgroud)
可见别名sudo到sudo + space以某种方式允许传递别名.这部作品zsh,bash并且sh,所以它不是一个特定的壳行为.
我正在尝试做一些非常类似于文档中的jquery路径示例的东西,但TS不断抛出TS2307(webpack编译正常):
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@client": [
"client",
],
"@suir": [
"../node_modules/semantic-ui-react/dist/commonjs", // not working
],
},
// …
},
"include": [
"*.d.ts",
"client/**/*",
"../node_modules/semantic-ui-react", // is this necessary?
],
Run Code Online (Sandbox Code Playgroud)
更改baseUrl到"."和更新includes,并paths没有什么区别(@client继续工作,@suir继续到不行).
更改"@suir"到"@suir/"或"@suir/*"(和附加/*到它的价值)也没有什么区别.
我这样做的原因是为了简化我的导入(我明确指定它们而不是从捆绑中提取命名导出以减少我的供应商包大小 - 节省大约1 MB):
import Button from 'semantic-ui-react/dist/commonjs/elements/Button'; // works
import Button from '@suir/elements/Button'; // not found
Run Code Online (Sandbox Code Playgroud)