我在Impala中使用SQL来编写此查询.我正在尝试将以YYYYMMDD格式存储的日期字符串转换为日期格式,以便运行如下查询:
SELECT datadate,
session_info
FROM database
WHERE datadate >= NOW() - INTERVAL 5 DAY
ORDER BY datadate DESC;
Run Code Online (Sandbox Code Playgroud)
由于>= NOW() - INTERVAL 5 DAY代码不能与YYYYMMDD字符串一起使用,我想找到一种方法将其转换为可用于此类查询的日期格式.我的想法是它应该看起来像这样(基于关于其他SQL查询编辑器的类似问题),但它在Impala中不起作用:
SELECT datadate,
session_info,
convert(datetime, '20141008', 102) AS session_date
FROM database
WHERE session_date >= NOW() - INTERVAL 5 DAY
ORDER BY session_date DESC;
Run Code Online (Sandbox Code Playgroud)
任何人都知道在Impala中如何做到这一点?
编辑:
我终于找到了解决问题的有效方法.没有尝试使用Impala的配置CAST或CONVERT在Impala中工作,但是下面的查询解决了问题并且完全可操作,允许对包含字符串值的列执行日期数学运算:
SELECT datadate,
session_info
FROM database
WHERE datadate >= from_unixtime(unix_timestamp(now() - interval 5 days), 'yyyyMMdd')
GROUP BY datadate
ORDER BY datadate DESC;
Run Code Online (Sandbox Code Playgroud) 我在尝试创建数据库时遇到错误.我安装了postgres,我已经成功完成了一些测试项目.而且,我没有看到这个错误.任何帮助都会很棒:
错误:
~/Desktop/elixir/restore $ mix ecto.create
** (Mix) The database for Restore.Repo couldn't be created: tcp connect: connection refused - :econnrefused
21:52:23.978 [error] GenServer #PID<0.150.0> terminating
** (Postgrex.Error) tcp connect: connection refused - :econnrefused
(db_connection) lib/db_connection/connection.ex:148: DBConnection.Connection.connect/2
(connection) lib/connection.ex:623: Connection.enter_connect/5
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
Run Code Online (Sandbox Code Playgroud) 如何在我计划与Ecto一起运行的查询中使用递归CTE的结果?例如,假设我有一个表,节点,结构如下:
-- nodes table example --
id parent_id
1 NULL
2 1
3 1
4 1
5 2
6 2
7 3
8 5
Run Code Online (Sandbox Code Playgroud)
我还有另一个表nodes_users结构如下:
-- nodes_users table example --
node_id user_id
1 1
2 2
3 3
5 4
Run Code Online (Sandbox Code Playgroud)
现在,我想抓住具有特定节点或其上方节点的所有用户,为了示例,我们选择具有id 8的节点.
我可以使用以下递归postgresql查询来执行此操作:
WITH RECURSIVE nodes_tree AS (
SELECT *
FROM nodes
WHERE nodes.id = 8
UNION ALL
SELECT n.*
FROM nodes n
INNER JOIN nodes_tree nt ON nt.parent_id = n.id
)
SELECT u.* FROM users u
INNER …Run Code Online (Sandbox Code Playgroud) 我有两个型号,Person并且Pet,我希望Person能够有很多宠物,但Pet到属于只有一个人:
defmodule MyApp.Person do
use MyApp.Web, :model
alias MyApp.Pet
schema "persons" do
field :name, :string
has_many :pets, Pet
timestamps()
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [])
|> validate_required([])
end
end
Run Code Online (Sandbox Code Playgroud)
和
defmodule MyApp.Pet do
use MyApp.Web, :model
alias MyApp.Person
schema "pets" do
field :name, :string
belongs_to :person, Person
timestamps()
end
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [])
|> validate_required([]) …Run Code Online (Sandbox Code Playgroud) 我的Phoenix API返回200POST请求的状态代码而不是201.200如果我没有设置状态代码,Phoenix默认使用.
这是样本回复.
conn |> json(%{created_at: response[:timestamp], notes: response[:notes], data: data})
Run Code Online (Sandbox Code Playgroud) 我有一个特定的控制器动作,我想要渲染没有任何布局.
我尝试在控制器级别没有插件的情况下渲染,但它没有用.
defmodule Hello.PageController do
use Hello.Web, :controller
plug :put_layout, nil
def landing(conn, _params) do
render conn, "landing.html"
end
end
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我正在使用rome 1.0为我的java应用程序生成RSS.
在我的java中:
SyndFeed feed = new SyndFeedImpl();
feed.setFeedType( "rss_2.0" );
feed.setTitle( "My Site" );
feed.setLink( "http://example.com" );
feed.setDescription( "Test Site." );
List<SyndEntry> entries = new ArrayList<SyndEntry>();
SyndEntry entry = null;
SyndContent description = null;
entry = new SyndEntryImpl();
entry.setTitle( "Entry1" );
entry.setLink( "http://example.com/entry1" );
entry.setPublishedDate( new Date() );
description = new SyndContentImpl();
description.setType("text/html");
description.setValue( "This is the content of entry 1." );
entry.setDescription( description );
entries.add( entry );
feed.setEntries(entries);
Writer writer = new FileWriter("/home/jr/Desktop/stream.xml");
SyndFeedOutput output = …Run Code Online (Sandbox Code Playgroud) 我试图得到像这样的ecto查询:
def find(searchterm) do
query = from c in Contact,
#where: fragment("? % ?", c.company_name, ^searchterm),
where: like(c.company_name, ^searchterm),
contacts = Repo.all(query)
{:ok, contacts}
end
Run Code Online (Sandbox Code Playgroud)
在我的表中,我有一个company_name"Asymptote".使用where:like/2我的查询如下所示:
SELECT c0."id", c0."company_id", c0."company_name" FROM "contacts" AS c0 WHERE (c0."company_name" LIKE $1) ["Asym"] (1.0ms)
Run Code Online (Sandbox Code Playgroud)
当pg_trm搜索取消注释时,它看起来像这样:
SELECT c0."id", c0."company_id", c0."company_name" FROM "contacts" AS c0 WHERE (c0."company_name" % $1) ["Asym"] (1.0ms)
Run Code Online (Sandbox Code Playgroud)
据我所知,查询看起来不错,但没有结果.由于我在向数据库添加"渐近线"之后添加了索引,我希望这就是为什么在pg_trm索引中找不到它,但为什么不喜欢/ 2或ilike/2工作?输入全名"Asymptote"时,我能够找到记录.
我是一个试图进入长生不老药的Ruby开发者.我正在尝试与API交互以学习一点Elixir.我基本上是在尝试发出http请求.在红宝石中,我试图做的事情看起来像这样.
require 'httparty'
url = "https://api.sportradar.us/nba/trial/v4/en/games/2016/11/05/schedule.json?api_key={api_key}"
response = HTTParty.get(url)
req = response.parsed_response
Run Code Online (Sandbox Code Playgroud)
非常简单明了.现在我有一个json解码响应,我可以在屏幕上显示数据.我怎么能用Elixir和Phoenix做到这一点?
我试图有一些变量属性值,并使用Maven配置文件来获得正确的输出.我已经为我的hibernate xml,log4j.properties做了这个,并没有问题.
所以它在项目#1中对我有用,我在/ src/main/resources下有一堆文件.我在maven中设置了属性和资源过滤,如下所示:
<properties>
<log.level>DEBUG</log.level>
</properties>
<profiles>
<profile>
<id>production</id>
<properties>
<log.level>INFO</log.level>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
Run Code Online (Sandbox Code Playgroud)
以上工作没有问题.但是,在我的项目#2中 - 我有一些具有可变属性的文件,但是它们位于/ src/main/webapp/WEB-INF下 - 我做的与上面相同,除了指向WEB-INF的目录它不起作用.我在项目#2上尝试将文件放在/ src/main/resources下并且它工作正常.
所以在我看来资源过滤有问题,当文件在/ src/main/webapp/WEB-INF下,但我需要文件在那里,所以它在生成战争时进入WEB-INF文件夹.
有没有人有关于如何做到这一点的指针?
以下是pom.xml中的以下snipet不起作用(资源过滤完全被忽略)
<properties>
<wsdl.url>http://stage/wsdl-url</wsdl.url>
</properties>
<profiles>
<profile>
<id>production</id>
<properties>
<wsdl.url>http://prod/wsdl-url</wsdl.url>
</properties>
</profile>
</profiles>
<build>
<resources>
<resource>
<directory>src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
Run Code Online (Sandbox Code Playgroud)