This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
deallocate tables; | |
prepare tables(text, text, text) as | |
SELECT c.TABLE_NAME, c.COLUMN_NAME, kcu.CONSTRAINT_NAME, c.DATA_TYPE, c.CHARACTER_MAXIMUM_LENGTH, tc.CONSTRAINT_TYPE, | |
CASE tc.CONSTRAINT_TYPE WHEN 'PRIMARY KEY' THEN CAST(1 AS BIt) ELSE CAST(0 AS Bit) END AS IsPrimaryKey, | |
(CASE ( | |
(SELECT CASE (LENGTH(pg_get_serial_sequence(c.TABLE_NAME, c.COLUMN_NAME)) > 0) WHEN true THEN 1 ELSE 0 END) + | |
(SELECT CASE (SELECT pgc.relkind FROM pg_class pgc WHERE pgc.relname = c.TABLE_NAME || '_' || c.COLUMN_NAME || '_' || 'seq') WHEN 'S"' THEN 1 ELSE 0 END)) | |
WHEN 0 THEN false ELSE true END) AS IsAuto, c.column_default | |
FROM information_schema.columns c | |
LEFT OUTER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select artists.id as artist_id, (select row_to_json(artist_albums) | |
from | |
( | |
select a.name, | |
( | |
select array_to_json(array_agg(albums)) | |
from albums where artist_id = a.id | |
) as albums | |
from artists as a where a.id = artists.id | |
) as artist_albums) as artist from artists where artists.id = 12 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS [Artist]; | |
CREATE TABLE [Artist] | |
( | |
[ArtistId] INTEGER NOT NULL, | |
[Name] NVARCHAR(120), | |
CONSTRAINT [PK_Artist] PRIMARY KEY ([ArtistId]) | |
); | |
-- BEGIN; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT nextval('my_sequence_name') FROM generate_series( 1, 100 ) n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original Stack Overflow Answer from http://stackoverflow.com/a/23506548/586518 | |
Original Code from SO answer: | |
```csharp | |
var value = await response.Content.ReadAsStringAsync(); | |
if (!response.IsSuccessStatusCode) | |
{ | |
var obj = new { message = "", ModelState = new Dictionary<string,string[]>() }; | |
var x = JsonConvert.DeserializeAnonymousType(value, obj); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
splitArray = Regex.Split(subjectString, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INSERT INTO "ClientDocuments" ("ClientDocumentId", body) VALUES (nextval('"ClientDocuments_ClientDocumentId_seq"'::regclass), cast('{"id":"' || lastval() || '", "name":"John"}' as json)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hacked-together make file for use with Harvard cs50 on-line course excercises | |
# Type terminal commands as follows: make EXE=yourFileName (don't add extensions) | |
# the compiler: gcc for C program, define as g++ for C+ use clang for Harvard stuff | |
CC = clang | |
# compiler flags: | |
# -g adds debugging information to the executable file | |
# -Wall turns on most, but not all, compiler warnings | |
CFLAGS = -g -Wall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT obj.name AS FK_NAME, | |
sch.name AS [schema_name], | |
tab1.name AS [table], | |
col1.name AS [column], | |
tab2.name AS [referenced_table], | |
col2.name AS [referenced_column] | |
FROM sys.foreign_key_columns fkc | |
INNER JOIN sys.objects obj | |
ON obj.object_id = fkc.constraint_object_id | |
INNER JOIN sys.tables tab1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- In Postgres I can do THIS for a table with a composite PK: | |
DELETE FROM [Building] WHERE (PropertyId, BuildingId) IN ((1,6),(1,7),(1,8),(1,9),(1,10)) | |
-- What is the SQL Server Equivelent? Or is there one? Am I stuck with some horrible nested subquery? |