CREATE OR REPLACE FUNCTION public.foo(str character varying)
RETURNS SETOF record
LANGUAGE plpgsql
AS $$
BEGIN
IF str = 'i' THEN
RETURN QUERY SELECT i, i*i FROM generate_series(1, 10) i;
ELSE
RETURN QUERY SELECT i, SQRT(i::float) FROM generate_series(1, 10) i;
END IF;
END;
$$
# select * from foo('i') as (key int, value int);
key | value
-----+-------
1 | 1
2 | 4
3 | 9
4 | 16
5 | 25
6 | 36
7 | 49
8 | 64
9 | 81
10 | 100
(10 rows)
# select * from foo('x') as (key int, value float);
key | value
-----+--------------------
1 | 1
2 | 1.4142135623730951
3 | 1.7320508075688772
4 | 2
5 | 2.23606797749979
6 | 2.449489742783178
7 | 2.6457513110645907
8 | 2.8284271247461903
9 | 3
10 | 3.1622776601683795
(10 rows)
CREATE OR REPLACE FUNCTION _Foo2(st TIMESTAMP, fin TIMESTAMP)
RETURNS TABLE (out_key INTEGER, out_tst timestamptz, out_val FLOAT) AS $$
DECLARE
BEGIN
RETURN QUERY EXECUTE FORMAT('
SELECT %I, %I, %I
FROM %I
WHERE %I BETWEEN ''%s'' AND ''%s'';
',
'in_key', 'in_tst', 'in_val', 'in_table', 'in_tst', st, fin);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION Foo(st TIMESTAMP, fin TIMESTAMP)
RETURNS TABLE (tstamp timestamptz, val float) AS $$
...
RETURN QUERY SELECT tstamp, val FROM hyptab WHERE tstamp >= st AND tstamp < fin;
END;
$$ LANGUAGE plpgsql;
INSERT INTO table (config, allowance, tablename) VALUES --,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Ph'']/Amperage', 3, 'float_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Ph'']/Voltage', 3, 'number_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Mc1'']/Amperage', 3, 'float_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Mc1'']/Voltage', 3, 'number_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Mc12'']/Amperage', 3, 'float_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Mc12'']/Voltage', 3, 'number_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Mc2'']/Amperage', 3, 'float_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''Mc2'']/Voltage', 3, 'number_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''An'']/Amperage', 3, 'float_actual')
,
('Station/Equip/Slot/Item[@key=''1'']/Supply/Item[@key=''An'']/Voltage', 3, 'number_actual')
;
INSERT INTO table (config, allowance, tablename) VALUES --</xsl:text><xsl:apply-templates/>
<xsl:text>;</xsl:text>
</xsl:template>
<xsl:template match="node()[@format]">
<xsl:variable name="allowance" select="Allowance/@value"/>
<xsl:text>, </xsl:text> <!-- Сюда добавлены запятая и перенос -->
<xsl:value-of select="concat('(', $apostrophe)"/>
<xsl:for-each select="ancestor::*">
<xsl:variable name="element" select="local-name()"/>
<xsl:value-of select="$element"/>
<xsl:if test="$element='Item'">
<xsl:value-of select="concat('[@key=', $apostrophe, $apostrophe, @key, $apostrophe, $apostrophe, ']')"/>
</xsl:if>
<xsl:text>/</xsl:text>
</xsl:for-each>
<xsl:choose>
<xsl:when test="starts-with(@format, 'N')">
<xsl:value-of select="concat(local-name(), $apostrophe, ', ', $allowance, ', ', $apostrophe, 'number_actual', $apostrophe, ')')"/> <!--убран вывод последней запятой -->
</xsl:when>
<xsl:when test="starts-with(@format, 'F')">
<xsl:value-of select="concat(local-name(), $apostrophe, ', ', $allowance, ', ', $apostrophe, 'float_actual', $apostrophe, ')')"/> <!--убран вывод последней запятой -->
</xsl:when>
<xsl:when test="starts-with(@format, 'D')">
<xsl:value-of select="concat(local-name(), $apostrophe, ', ', $allowance, ', ', $apostrophe, 'decimal_actual', $apostrophe, ')')"/> <!--убран вывод последней запятой -->
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat(local-name(), $apostrophe, ', ', $allowance, ', ', $apostrophe, 'string_actual', $apostrophe, ')')"/> <!--убран вывод последней запятой -->
</xsl:otherwise>
</xsl:choose>
<xsl:text> </xsl:text>
</xsl:template>
<xsl:template match="text()"/>
</xsl:stylesheet>
insert into table_Number (key, tstamp)
select * from (
select row_number() over () n, t
from generate_series(NOW() - INTERVAL '90 days', NOW(),'1 min') t
) sq
where n <= 300
select *
from (
select sum(quantity) over (partition by path_) quantity,
row_number() over (partition by path_) rn
--,h.*, p.*, r.*
from (
SELECT cid, par_cid, rname,
sys_connect_by_path(cid,'/') path_,
sys_connect_by_root(cid) product_cid
FROM catalog
START WITH cid in (
-- возможно есть способ определить листья
-- без использования дополнительного вызова
select distinct rcid from products
)
CONNECT BY PRIOR par_cid = cid
) h
join products p on (h.product_cid = p.rcid)
join records r ...
)
where rn = 1
public abstract class Transport {
public int MaxSpeed { get; private set; }
public Transport(int maxSpeed) {
MaxSpeed = maxSpeed;
}
public string Run(int speed)
=> $"Скорость движения транспорта {(speed <= MaxSpeed ? "в пределах нормы" : "выше максимальной")}";
}
public class Car : Transport {
public Car() : base(300) {}
}
public class Bike : Transport {
public Bike() : base(40) {}
}
DECLARE @T TABLE ( M DATETIME2(0))
INSERT @T VALUES ('2017-02-01 15:00:43'),
('2017-03-18 10:30:10'),
('2017-12-11 01:21:55'),
('2017-12-11 15:33:03'),
('2017-03-18 10:30:10'),
('2017-02-22 08:40:42'),
('2017-06-06 23:59:40')
SELECT DISTINCT MB.M AS [Start],
( SELECT TOP 1 M FROM @T AS ME WHERE (ME.M > MB.M) ORDER BY ME.M ) AS [End]
FROM @T AS MB
UNION
SELECT M, M
FROM @T
GROUP BY M
HAVING COUNT(M) > 1
ORDER BY 1, 2
select s.Name
, sum(nvl(o.Amount, 0)) as Quantity
from Sellers as s,
Orders as o
where s.id = o.Salesperson_id
and o.Order_date is not null
and o.Order_date > to_date('20091231','YYYYMMDD') /*если это date*/
group by s.id, s.Name
having count(o.Salesperson_id) > 1
order by sum(nvl(o.Amount, 0)) desc
offset 0 rows fetch next 1 rows only
// To parse this JSON data, add NuGet 'Newtonsoft.Json' then do:
//
// using QuickType;
//
// var data = GettingStarted.FromJson(jsonString);
//
// For POCOs visit quicktype.io?poco
//
namespace QuickType
{
using System;
using System.Net;
using System.Collections.Generic;
using Newtonsoft.Json;
public partial class GettingStarted
{
[JsonProperty("measures")]
public Measures Measures { get; set; }
[JsonProperty("number2")]
public Number2 Number2 { get; set; }
[JsonProperty("items")]
public Items Items { get; set; }
[JsonProperty("number1")]
public Number1 Number1 { get; set; }
[JsonProperty("user")]
public User User { get; set; }
}
public partial class Measures
{
[JsonProperty("2")]
public OtherThe1 The2 { get; set; }
[JsonProperty("1")]
public OtherThe1 The1 { get; set; }
[JsonProperty("3")]
public OtherThe1 The3 { get; set; }
}
public partial class OtherThe1
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
}
public partial class Number2
{
[JsonProperty("2")]
public OtherOtherOtherThe1 The2 { get; set; }
[JsonProperty("1")]
public OtherOtherOtherThe1 The1 { get; set; }
[JsonProperty("3")]
public OtherOtherOtherThe1 The3 { get; set; }
}
public partial class OtherOtherOtherThe1
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("parent")]
public string Parent { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
}
public partial class Items
{
[JsonProperty("2")]
public The1 The2 { get; set; }
[JsonProperty("1")]
public The1 The1 { get; set; }
[JsonProperty("3")]
public The1 The3 { get; set; }
}
public partial class The1
{
[JsonProperty("measure")]
public string Measure { get; set; }
[JsonProperty("number")]
public string Number { get; set; }
[JsonProperty("foxproID")]
public string FoxproID { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("producer")]
public string Producer { get; set; }
[JsonProperty("suodID")]
public string SuodID { get; set; }
}
public partial class Number1
{
[JsonProperty("2")]
public OtherOtherThe1 The2 { get; set; }
[JsonProperty("1")]
public OtherOtherThe1 The1 { get; set; }
[JsonProperty("3")]
public OtherOtherThe1 The3 { get; set; }
}
public partial class OtherOtherThe1
{
[JsonProperty("description")]
public string Description { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
public partial class User
{
[JsonProperty("login")]
public string Login { get; set; }
[JsonProperty("ip")]
public string Ip { get; set; }
[JsonProperty("number")]
public long Number { get; set; }
}
public partial class GettingStarted
{
public static GettingStarted FromJson(string json) => JsonConvert.DeserializeObject<GettingStarted>(json, Converter.Settings);
}
public static class Serialize
{
public static string ToJson(this GettingStarted self) => JsonConvert.SerializeObject(self, Converter.Settings);
}
public class Converter
{
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
DateParseHandling = DateParseHandling.None,
};
}
}